Skip to content

Commit

Permalink
Fix the diagnostic issue and no_diff issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhangNV committed Oct 10, 2024
1 parent 1013d73 commit 5a1ab65
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
54 changes: 36 additions & 18 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ namespace Slang

void cloneModifiers(Decl* dest, Decl* src);
void setFuncTypeIntoRequirementDecl(CallableDecl* decl, FuncType* funcType);

bool m_checkForSynthesizedCtor = false;
};

struct SemanticsDeclRedeclarationVisitor
Expand Down Expand Up @@ -2099,6 +2097,29 @@ namespace Slang
return ctorList;
}

static void checkSynthesizedConstructorWithoutDiagnostic(SemanticsVisitor* visitor, ConstructorDecl* decl)
{
DiagnosticSink tempSink;
SemanticsContext subContext = visitor->withSink(&tempSink);
subContext.setCheckForSynthesizedCtor(true);
SemanticsDeclHeaderVisitor subVisitor(subContext);
subVisitor.dispatch(decl);

if (tempSink.getErrorCount() > 0)
{
auto structDecl = as<StructDecl>(decl->parentDecl);
// As we already know that this is a synthesized constructor is wrong, and we already remove it, we
// will prevent the future checking of this constructor by setting the state to the final state.
// TODO: This might be too hacky?
decl->setCheckState(DeclCheckState::DefinitionChecked);
structDecl->members.remove(decl);
structDecl->invalidateMemberDictionary();
structDecl->buildMemberDictionary();
structDecl->m_synthesizedCtorMap.remove((int)ConstructorDecl::ConstructorTags::MemberInitCtor);
}
return;
}

void SemanticsDeclHeaderVisitor::visitStructDecl(StructDecl* structDecl)
{
// As described above in `SemanticsDeclHeaderVisitor::checkVarDeclCommon`,
Expand Down Expand Up @@ -7639,6 +7660,18 @@ namespace Slang

void SemanticsDeclBodyVisitor::visitFunctionDeclBase(FunctionDeclBase* decl)
{
if (auto constructorDecl = as<ConstructorDecl>(decl))
{
// When checking the synthesized constructor, it's possible to hit error, but we don't want to
// report this error, because this function is not created by user. Instead, when we detect this
// error, we will remove this synthesized constructor from the struct.
if (constructorDecl->containsTag(ConstructorDecl::ConstructorTags::MemberInitCtor) && !m_checkForSynthesizedCtor)
{
checkSynthesizedConstructorWithoutDiagnostic(this, constructorDecl);
return;
}
}

auto newContext = registerDifferentiableTypesForFunc(decl);
if (const auto body = decl->body)
{
Expand Down Expand Up @@ -8748,9 +8781,7 @@ namespace Slang
SLANG_ABORT_COMPILATION(msg.produceString().begin());
}
}

MemberExpr* memberExpr = createMemberExpr(thisExpr, ctor->ownedScope, member);

auto assign = m_astBuilder->create<AssignExpr>();
assign->left = memberExpr;
assign->right = initExpr;
Expand Down Expand Up @@ -9371,20 +9402,7 @@ namespace Slang
// error, we will remove this synthesized constructor from the struct.
if (decl->containsTag(ConstructorDecl::ConstructorTags::MemberInitCtor) && !m_checkForSynthesizedCtor)
{
DiagnosticSink tempSink;
SemanticsContext subContext = withSink(&tempSink);
SemanticsDeclHeaderVisitor subVisitor(subContext);
subVisitor.m_checkForSynthesizedCtor = true;
subVisitor.dispatch(decl);

if (tempSink.getErrorCount() > 0)
{
auto structDecl = as<StructDecl>(decl->parentDecl);
structDecl->members.remove(decl);
structDecl->invalidateMemberDictionary();
structDecl->buildMemberDictionary();
structDecl->m_synthesizedCtorMap.remove((int)ConstructorDecl::ConstructorTags::MemberInitCtor);
}
checkSynthesizedConstructorWithoutDiagnostic(this, decl);
return;
}

Expand Down
7 changes: 7 additions & 0 deletions source/slang/slang-check-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,10 @@ namespace Slang

OrderedHashSet<Type*>* getCapturedTypePacks() { return m_capturedTypePacks; }

void setCheckForSynthesizedCtor(bool checkForSynthesizedCtor)
{
m_checkForSynthesizedCtor = checkForSynthesizedCtor;
}
private:
SharedSemanticsContext* m_shared = nullptr;

Expand Down Expand Up @@ -1107,6 +1111,9 @@ namespace Slang
ExpandExpr* m_parentExpandExpr = nullptr;

OrderedHashSet<Type*>* m_capturedTypePacks = nullptr;

// Flag to indicate whether this check is to check a synthesized constructor
bool m_checkForSynthesizedCtor = false;
};

struct OuterScopeContextRAII
Expand Down

0 comments on commit 5a1ab65

Please sign in to comment.