Skip to content

Conversation

@rainers
Copy link
Member

@rainers rainers commented Aug 16, 2013

build TypeInfo in semantic, not during code-gen. This fixes RTInfo generation used by the precise GC implementation.

http://d.puremagic.com/issues/show_bug.cgi?id=10786

happens if the TypeInfo is referred to during the semantic3 pass, but is added to a module that has already completed the semantic3 step. This is fixable using the new deferred-semantic3 list. But the fixed version often triggers the next bug:

http://d.puremagic.com/issues/show_bug.cgi?id=10442

The problem is that the TypeInfo records are generated only from the glue or backend layer (e2ir.c or toobj.c) by calling Type::getTypeInfo(NULL), which outputs the TypeInfo without further analysis to the object file.
This ignores the RTInfo definition and just writes 0/1 depending on whether there are pointer fields in the struct/class or not.

Assuming that it is a bug to call Type::getTypeInfo(NULL) after semantic3 is finished, this patch forces the creation of the TypeInfo records during semantic for those expressions that later need them in the glue layer. A
problem with that approach is that it adds the TypeInfo of imported code into the object file (as COMDAT) if it is used in CTFE or type inference (similar to template functions). This makes http://d.puremagic.com/issues/show_bug.cgi?id=10831 show up more often.

Another problem is that the type of expressions is often changed later by implicite/explicite
conversions. This makes it hard to actually find those changes and generate TypeInfo
records for the new types aswell, leaving the original records unused.

I've made calls to getTypeInfo(NULL) that would trigger the creation of new TypeInfo records an ICE, but we might want to change the ICE to a warning to avoid breaking code that does not rely on proper TypeInfo.

@rainers
Copy link
Member Author

rainers commented Aug 19, 2013

It seems this pull request has stalled the Win32 tester. Can someone kill the process? Is it terminated automatically after some timeout?

@rainers
Copy link
Member Author

rainers commented Aug 23, 2013

Now this passes the tests, anyone care to comment if this going in the right direction?
It is vital for these issues to be fixed to continue with the precise GC.

src/typinf.c Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of copy/pasta common code here. Shouldn't inheritance be used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more or less the same duplication as in the toDt methods as it extracts their referenced TypeInfo. Both semantic3 and toDt might use common implementation for groups of classes with the referenced type in some overridable method but it could also complicate the codee and add boilerplate.

@rainers
Copy link
Member Author

rainers commented Oct 4, 2013

To make this work with recent changes I had to add avoiding to generate code for template instances that failed to instantiate during __traits(compiles). I know the method name "isInErrorTree" is horrible, but I could not find a better one.

@rainers
Copy link
Member Author

rainers commented Nov 19, 2013

Fixed, now contains a fix for https://d.puremagic.com/issues/show_bug.cgi?id=11427, but probably #2757 is a more complete fix for it.

@rainers
Copy link
Member Author

rainers commented Nov 30, 2013

The failure is caused by abuse of https://d.puremagic.com/issues/show_bug.cgi?id=11645

@rainers
Copy link
Member Author

rainers commented Jan 5, 2014

fixed conflicts and rebased.

I had to disable semantic analysis of unittests on non-root modules to not expect type infos generated in a library which is not compiled with unittests enabled.
Maybe this is an optimization that makes sense in general.

@DmitryOlshansky
Copy link
Member

Needs rebase

@rainers
Copy link
Member Author

rainers commented Jan 11, 2014

now rebased.

src/class.c Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc->module->isRoot()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original change predates the introduction of isRoot, will change.

@rainers
Copy link
Member Author

rainers commented Jan 15, 2014

@WalterBright Thanks for review. Unfortunately the SSD with my D stuff on it is broken and I'm still hoping for repair without data loss, so I cannot do a lot right now.

Do you agree with the general design of eagerly creating the necessary type infos? As described in the summary, it might generate more type info records than absolutely necessary.

@rainers
Copy link
Member Author

rainers commented Jan 17, 2014

Updated according to comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how to fix this message. S produced an error, so it doesn't display as "S". Should it be removed?

@WalterBright
Copy link
Member

@rainers thanks for the quick responses, but we shouldn't pull this until after 2.065 is out.

@dnadlinger
Copy link
Contributor

@WalterBright: So what is the point of the release branch then? Holding back on all merges for an indefinite amount of time can be an incredible demotivator for people working on the compiler.

@rainers
Copy link
Member Author

rainers commented Mar 9, 2014

Redone this PR. It now uses semanticTypeInfo from #3256 most of the time, though it must be called quite often.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @rainers!

Bugzilla references

Auto-close Bugzilla Severity Description
10442 normal RTInfo generation can fail for structs defined in imported modules

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#2480"

@rainers
Copy link
Member Author

rainers commented Sep 18, 2020

dlang-bot keeps commenting, because it fails to find its comment in the first 100 comments and thus thinks it must add the initial comment.

Thanks for the info, I was already wondering. But it didn't bother me too much ;-)

@rainers rainers requested a review from Geod24 as a code owner September 18, 2020 16:53
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @rainers!

Bugzilla references

Auto-close Bugzilla Severity Description
10442 normal RTInfo generation can fail for structs defined in imported modules

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#2480"

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @rainers!

Bugzilla references

Auto-close Bugzilla Severity Description
10442 normal RTInfo generation can fail for structs defined in imported modules

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#2480"

@AndrewEdwards
Copy link
Contributor

@dnadlinger, @WalterBright, @kinke, @Geod24 , @RazvanN7

Gentlemen, this request is pending your review/approval

@rainers
Copy link
Member Author

rainers commented Sep 20, 2020

While this passes now (but for some styling and C++ header updates), let me point out a couple of thoughts:

  • I can extract a couple of fixes into separate PRs
  • this shows some of the patches that will be necessary for generic TypeInfo definition as a template under the current design.
  • it might generate some more TypeInfo's pessimistically that might not always be necessary, but that's hard to predict. So it might have some (probably small) impact on compilation time
  • additional TypeInfo's can introduce other dependencies that might cause link errors that were not there before (but mostly should have been)
  • I expect that erroring out if the RTInfo is not generated will happen in the wild, it might be better to make it a warning/message only to avoid breaking code that doesn't care about correct TypeInfo.

I'm not a fan of the current design, though: eager generation of TypeInfo trying to predict what the glue layer might do is error-prone and inefficient.
I imagine that the lowerings to D runtime calls done in the glue layer (and most of the lowerings done in the semantic-passes) should be done in some semantic4-pass ofter semantic3 is complete:

  • if "user-code" is error-free after the semantic3-pass, correct lowerings should not produce other (confusing) errors
  • semantic4 can still call other semantics on the new code, so e.g. TypeInfo is only generated if the actual call is generated.
  • semantic4 could also be the place for templated associative and dynamic array implementations
  • CTFE still needs to run in the semantic3-pass
  • it will reduce the code of the glue layer that needs to be reimplemented in LDC and GDC.

@AndrewEdwards
Copy link
Contributor

@dnadlinger, @WalterBright, @kinke, @Geod24 , @RazvanN7

Gentlemen, this request needs your attention, review and approval

@Imperatorn
Copy link
Contributor

Omg, is this from 2013? 😱

Copy link
Contributor

@MoonlightSentinel MoonlightSentinel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general notes/questions:

  • why does this PR add more eager TypeInfo generation (e.g. semanticTypeInfo in dcast.d) as well as more lazy generation (e.g. verifyTypeInfo in expressionsem.d).
  • refactorings should be done as separate PR's
  • this needs a lot more tests coverage (see CodeCov)

* Returns:
* true if struct is all zeroes
*/
final bool isZeroInit()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this function alongside TypeStruct.isZeroInit?

};

FuncDeclaration *search_toString(StructDeclaration *sd);
enum ZeroInit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum class can now be used

}
}

final void generateRTInfo(AggregateDeclaration ad, Scope* sc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DDoc comment

@12345swordy
Copy link
Contributor

cc @AndrewEdwards @RazvanN7

@Imperatorn
Copy link
Contributor

@rainers What needs fixing before we can merge? ☀️

@Imperatorn
Copy link
Contributor

A decade has passed

@schveiguy
Copy link
Member

@rainers is this still a valid issue? I noticed on the bug report, you said you cannot reproduce any more.

@rainers
Copy link
Member Author

rainers commented Aug 25, 2025

@schveiguy I tried the test case from this PR a couple of days ago, and it still failed. I haven't investigated further but I suspect most of the changes here are obsolete as less typeinfo is required now, so semanticTypeInfo() calls could even be removed. Even if I can figure this out, a new PR will probably simpler...

@schveiguy
Copy link
Member

Alright, let's close it to get it off the todo list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.