diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-05-11 13:56:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-11 13:56:14 -0700 |
| commit | 5e604a6f39ef8e8086702d41113ea78856804c99 (patch) | |
| tree | 035a4de9b84bdc04f377344dcaea931aa1896fa4 /source/slang/check.cpp | |
| parent | 10c0ffa7de111bd2c0096015bba5ca2110d03bc1 (diff) | |
Cleanups around behavior when the compiler fails (#553)
* Cleanups around behavior when the compiler fails
* Add another case where we try to `noteInternalErrorLoc()` if an exception in thrown. This one is the in the logic for emitting an IR instruciton. This could be improved by adding another layer at the function level (as a catch-all for instructions with no location), but something is better than nothing.
* Change a bunch of `assert()`s over to `SLANG_ASSERT()`s, so that we can theoretically take more control over them (e.g., make release builds with asserts enabled)
* Some other small cleanups around the assertions we perform.
In the survey I made, I didn't really see many obvious "smoking gun" cases where we could produce a significantly better error message for some of the unimplemented/unexpected paths, other than to actually implement the missing functionality.
* fixup
Diffstat (limited to 'source/slang/check.cpp')
| -rw-r--r-- | source/slang/check.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index a94812687..67c747861 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -3021,7 +3021,7 @@ namespace Slang void ValidateFunctionRedeclaration(FuncDecl* funcDecl) { auto parentDecl = funcDecl->ParentDecl; - SLANG_RELEASE_ASSERT(parentDecl); + SLANG_ASSERT(parentDecl); if (!parentDecl) return; Decl* childDecl = funcDecl; @@ -3094,7 +3094,7 @@ namespace Slang // consider if their generic signatures match. if (genericDecl) { - assert(prevGenericDecl); + SLANG_ASSERT(prevGenericDecl); // already checked above if (!doGenericSignaturesMatch(genericDecl, prevGenericDecl)) continue; @@ -4436,6 +4436,9 @@ namespace Slang // in order for checking to suceed. struct ConstraintSystem { + // A source location to use in reporting any issues + SourceLoc loc; + // The generic declaration whose parameters we // are trying to solve for. RefPtr<GenericDecl> genericDecl; @@ -4750,7 +4753,7 @@ namespace Slang return left; else { - SLANG_ASSERT(rightFlavor > leftFlavor); + SLANG_ASSERT(rightFlavor > leftFlavor); // equality was handles at the top of this function return right; } } @@ -5377,13 +5380,13 @@ namespace Slang return true; auto genericDeclRef = candidate.item.declRef.As<GenericDecl>(); - assert(genericDeclRef); + SLANG_ASSERT(genericDeclRef); // otherwise we wouldn't be a generic candidate... // We should have the existing arguments to the generic // handy, so that we can construct a substitution list. RefPtr<GenericSubstitution> subst = candidate.subst.As<GenericSubstitution>(); - assert(subst); + SLANG_ASSERT(subst); subst->genericDecl = genericDeclRef.getDecl(); subst->outer = genericDeclRef.substitutions.substitutions; @@ -5853,15 +5856,15 @@ namespace Slang { auto constraintDecl1 = fstWit->declRef.As<TypeConstraintDecl>(); auto constraintDecl2 = sndWit->declRef.As<TypeConstraintDecl>(); - assert(constraintDecl1); - assert(constraintDecl2); + SLANG_ASSERT(constraintDecl1); + SLANG_ASSERT(constraintDecl2); return TryUnifyTypes(constraints, constraintDecl1.getDecl()->getSup().type, constraintDecl2.getDecl()->getSup().type); } } - throw "unimplemented"; + SLANG_UNIMPLEMENTED_X("value unification case"); // default: fail return false; @@ -6111,6 +6114,7 @@ namespace Slang if (auto extGenericDecl = GetOuterGeneric(extDecl)) { ConstraintSystem constraints; + constraints.loc = extDecl->loc; constraints.genericDecl = extGenericDecl; if (!TryUnifyTypes(constraints, extDecl->targetType.Ptr(), type)) @@ -6229,12 +6233,13 @@ namespace Slang // so that the resulting inner declaration can be applicable in // a particular context... DeclRef<Decl> SpecializeGenericForOverload( - DeclRef<GenericDecl> genericDeclRef, - OverloadResolveContext& context) + DeclRef<GenericDecl> genericDeclRef, + OverloadResolveContext& context) { checkDecl(genericDeclRef.getDecl()); ConstraintSystem constraints; + constraints.loc = context.loc; constraints.genericDecl = genericDeclRef.getDecl(); // Construct a reference to the inner declaration that has any generic @@ -6363,7 +6368,7 @@ namespace Slang // We expect the parent of the generic type parameter to be a generic... auto genericDeclRef = typeDeclRef.GetParent().As<GenericDecl>(); - assert(genericDeclRef); + SLANG_ASSERT(genericDeclRef); for(auto constraintDeclRef : getMembersOfType<GenericTypeConstraintDecl>(genericDeclRef)) { @@ -7585,7 +7590,7 @@ namespace Slang bool isPrimaryDecl( CallableDecl* decl) { - assert(decl); + SLANG_ASSERT(decl); return (!decl->primaryDecl) || (decl == decl->primaryDecl); } |
