[stable] Fix #21359 - Merge more types in substWildTo()#21361
[stable] Fix #21359 - Merge more types in substWildTo()#21361dlang-bot merged 3 commits intodlang:stablefrom
substWildTo()#21361Conversation
|
Thanks for your pull request and interest in making D better, @kinke! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
…isn't merged yet
| objfile="${OUTPUT_BASE}${OBJ}" | ||
| $DMD -c -m${MODEL} -allinst -of${objfile} ${EXTRA_FILES}/${TEST_NAME}a.d -I${EXTRA_FILES} | ||
|
|
||
| # This test is brittle and might break in the future. |
There was a problem hiding this comment.
How about checking for duplicate symbols in general:
! nm -j bla.o | uniq -d | read
worked for the test case.
There was a problem hiding this comment.
I wanted to check that the symbol we are looking for is emitted once at least. E.g., in case -allinst in the future doesn't emit any TypeInfos for the test case, as none are actually required - no template is really instantiated in the root module.
Of course other fail_compilation tests now fail, with uglier 'forward reference' errors coming from the glue layer now, without a Loc. :(
There was a problem hiding this comment.
I wanted to check that the symbol we are looking for is emitted once at least.
Ok.
Of course other fail_compilation tests now fail, with uglier 'forward reference' errors coming from the glue layer now, without a Loc. :(
These are messages from the glue layer. I guess you can avoid them if the nextOf().merge().deco check is only added for case Taarray.
There was a problem hiding this comment.
Oh, read your suggestion just now after pushing a version which doesn't do the nested merge() if .next is a TypeFunction. That seems to be enough to not worsen the existing forward-ref errors, but that special case is obviously ugly...
Edit: I did check whether #21350 might be enough too, but no, it doesn't seem to affect these forward-ref errors.
There was a problem hiding this comment.
but that special case is obviously ugly...
I think it would be ok if implemented as a case Tfunction instead of extra checks in the generic case.
There was a problem hiding this comment.
I'm checking type.next, not the type itself.
There was a problem hiding this comment.
I guess it could be beneficial to move the if (type.deco) return type; before the switch though - the switch seems to be exclusively reserved for skipping the merge and returning type as-is (edit: modulo potential merge() calls for nested types, which can hopefully never affect type.deco).
There was a problem hiding this comment.
Ah, sorry, missed that.
Then my suggestion to only change the AA case could be an option:
case Taarray:
if (!type.isTypeAArray().index.merge().deco)
return type;
if (!type.nextOf().merge().deco)
return type;
break;as I see deco being used in a lot of places to check for resolved semantic. More regressions looming...
The bad types come from makeNakedAssociativeArray. substWildTo doesn't return a merged type in some cases. Adding .merge() in makeNakedAssociativeArray helps bla.d, but probably fixing it in substWildTo is better:
dmd/compiler/src/dmd/typesem.d
Line 7349 in 8d90d93
shoud return
t.merge().
There was a problem hiding this comment.
Thx for digging further!
but probably fixing it in
substWildTois better
Yeah I guess there we also don't need a special case for TypeFunctions (no qualified TypeFunctions I hope, only qualified function pointers/delegates). After a superficial glance, those seem to be an ugly special case, e.g., there are 3 occurrences of this comment in that file:
dmd/compiler/src/dmd/typesem.d
Lines 2748 to 2753 in 8d90d93
Edit: Oh well, TypeFunction is hugely special-cased in that function already, should have taken a look at the linked context first. ;)
There was a problem hiding this comment.
those seem to be an ugly special case, e.g., there are 3 occurrences of this comment in that file
Incidentally, substWildTo() does merge the TypeFunction it returns, not only copying the deco:
dmd/compiler/src/dmd/typesem.d
Lines 7378 to 7396 in 8d90d93
FWIW, I've tried a t.deco = merge(t).deco; return t; instead, but that alone didn't fix the testcase.
compiler/src/dmd/typesem.d
Outdated
| return type; | ||
| if (auto next = type.nextOf()) | ||
| { | ||
| // don't try to merge TypeFunctions (can shift forward-reference errors from the frontend to the glue layer, without Loc) |
There was a problem hiding this comment.
don't try to merge TypeFunctions
seems a bit misleading, maybe add "with incomplete return type"
There was a problem hiding this comment.
According to my results (#21350 didn't fix it), I don't think it's restricted to those without a TypeFunction.next themselves.
rainers
left a comment
There was a problem hiding this comment.
Indeed, the special cases around deco make changes rather brittle. I guess this change is the one with the least unexpected side effects while making substWildTo more consistent.
substWildTo()
No description provided.