Cleanup the hack code for the default ctor overload #5138
Labels
goal:forward looking
Feature needed at a later date, not connected to a specific use case.
Milestone
Backgroud:
This sub-task is split from #3406.
I wrap up Arial's PR #4854 to a new PR #5107 with some minor issues solved.
However, there still be lots of comments could potential involve large change on this PR.
We should not make one PR has infinitely long conversion and unlimited problems solved, so this task is create to only spot this issue.
We have a big issue in the implementation of the default ctor, where if there is no initExpr associated members or IDefaultInitializable inheritance in a struct, we will delete the ctor to avoid some warnings. This will bring us a bigger issue that we have to implement some hack code to overload the constructor invoke expression, e.g.
For the above code, because we remove the default ctor, it means that
S()
is unavailable anymore. This will throw compiler error that "S() is not found". So we implement some hacky code to deal with this issuehttps://github.com/shader-slang/slang/pull/5107/files/2b6f7a26688b60a74fde979fbfff28a24a493e5c#diff-2eecdb041b541df14ab93a0cfe35b4e0fbbcb63ef7fdcb004401829bfacdeb77R2400.
The original motivation to delete the ctor is to handle this case
compiler will report a warning that
variable x is not initialized
, the reason is becausex
has neither initEpxr nor inherits from IDefaultInitializable, our synthesized default ctor won't initializex
.This is not a good reason to delete the default ctor, we should either default very member in the default ctor no matter it has an initExpr.
This sub-task will track the effort to make the PR achieve this goal.
Specifically, the high level solution should be:
visitAggTypeDecl
, always make sure to visit all the members first.visitVarDecl
, if we are visiting a member field declaration, we check if the member field has ainitExpr
or if the member field's type isIDefaultInitializable
, if so, mark the parent declNeedDefaultCtor
.visitAggTypeDecl
, if the decl has been markedNeedDefaultCtor
, proceed to synthesize the default ctor. (Nor for now)initExpr
.We should make sure that the step 1, 2 and 4 be implemented in this task.
The text was updated successfully, but these errors were encountered: