Skip to content

Comments

fix Issue 18480 - dmd 2.079 hangs#7930

Merged
MartinNowak merged 1 commit intodlang:stablefrom
timotheecour:pr_fix_18480
Feb 24, 2018
Merged

fix Issue 18480 - dmd 2.079 hangs#7930
MartinNowak merged 1 commit intodlang:stablefrom
timotheecour:pr_fix_18480

Conversation

@timotheecour
Copy link
Contributor

No description provided.

@dlang-bot
Copy link
Contributor

dlang-bot commented Feb 21, 2018

Thanks for your pull request and interest in making D better, @timotheecour! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Auto-close Bugzilla Severity Description
18480 regression dmd 2.079 hangs

@timotheecour timotheecour changed the title fix #18480 fix Issue 18480 dmd 2.079 hangs Feb 21, 2018
@timotheecour timotheecour changed the title fix Issue 18480 dmd 2.079 hangs fix Issue 18480 - dmd 2.079 hangs Feb 21, 2018
@wilzbach
Copy link
Contributor

Thanks, but mind the CI failures + please add a test for it to fail_compilation.

src/dmd/access.d Outdated
auto aliasee = ad.toAlias();
if (aliasee.isFuncAliasDeclaration || aliasee.isOverDeclaration)
{
error(ad.loc, "`alias X = X` not allowed (with `X = %s`)", ad.toChars());
Copy link
Contributor

@JinShil JinShil Feb 21, 2018

Choose a reason for hiding this comment

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

Why is it not allowed? What's the fundamental issue? Also, isn't there a way to print the actual syntax the user wrote in their source code (s.toChars() maybe), rather than giving them a syntax pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be fixed with latest commit

the issue is to fix the infinite loop.

Also, isn't there a way to print the actual syntax the user wrote

alias X=X is more searchable in bug reports

@timotheecour timotheecour changed the title fix Issue 18480 - dmd 2.079 hangs [WIP] fix Issue 18480 - dmd 2.079 hangs Feb 21, 2018
@dlang-bot dlang-bot added the Review:WIP Work In Progress - not ready for review or pulling label Feb 21, 2018
@wilzbach
Copy link
Contributor

Why is it not allowed? What's the fundamental issue?

See also: #6676 (comment)

@timotheecour
Copy link
Contributor Author

Thanks, but mind the CI failures + please add a test for it to fail_compilation.

seems to (at least so far) pass now;
not sure how to reduce (haven't tried dustmite on this though)
help welcome if anyone wants to provide a reduced test case

@timotheecour timotheecour changed the title [WIP] fix Issue 18480 - dmd 2.079 hangs fix Issue 18480 - dmd 2.079 hangs Feb 21, 2018
@MartinNowak MartinNowak changed the base branch from master to stable February 21, 2018 06:48
@RazvanN7
Copy link
Contributor

This solves this issue : https://issues.dlang.org/show_bug.cgi?id=18432

@MartinNowak
Copy link
Member

This fixes the issue more on the symptom side (by detecting the infinite loop in the weird overload "data structure"), I'd like to spent a bit more time to better understand what's happening (and have a good test case) and to address the issue around AliasDeclaration::overloadInsert where the loop is created.
An interesting aspect, we're checking protection/visibility on the unresolved alias to support public aliases to private symbols.

The current overload structure is unfortunately a horrible implementation that needs a design change and some refactoring. Would be great if we just collected all overloads in a plain array and checked for duplicates during semantic, rather than using those recursive, polymorphic calls to overloadInsert.
Also there are 2 helper classes of little use (FuncAliasDeclaration and OverDeclaration) that are only needed to deal with the fact that overloading aliases depends on whether the aliasee is overloadable.

@timotheecour
Copy link
Contributor Author

@MartinNowak how about merging this in the meantime to avoid having this bug in git master? one can always revert this once a better solution comes along. This PR doesn't make anything worse but it fixes the above (serious) bug

@JinShil
Copy link
Contributor

JinShil commented Feb 23, 2018

Reduced test case

--- moduleA.d
module moduleA;

template TestTemplate() { }

--- moduleB.d
module moduleB;

import moduleA : TestTemplate;
alias TestTemplate = TestTemplate;

--- main.d
import moduleB;

alias TestTemplate = moduleB.TestTemplate;

void main() { }

compile with: dmd main.d moduleA.d moduleB.d

@jacob-carlborg
Copy link
Contributor

@timotheecour 65 commits? I think you made a mistake with Git.

@timotheecour timotheecour changed the base branch from stable to master February 23, 2018 19:45
@timotheecour
Copy link
Contributor Author

@timotheecour 65 commits? I think you made a mistake with Git.

fixed... is targetting dlang:master ok in this PR?

@timotheecour
Copy link
Contributor Author

@JinShil thanks, added reduced test

@timotheecour timotheecour changed the base branch from master to stable February 23, 2018 20:40
@timotheecour
Copy link
Contributor Author

PTAL, rebased against stable;
GDC fails but seems unrelated to this PR : https://semaphoreci.com/dlang/dmd-2/branches/pull-request-7930/builds/8 (Unknown compiler 'gdc-' ??)

@timotheecour timotheecour force-pushed the pr_fix_18480 branch 2 times, most recently from 9dd51f9 to 9de5cd9 Compare February 23, 2018 22:25
@MartinNowak
Copy link
Member

import moduleB; alias TestTemplate = moduleB.TestTemplate; void main() { }

This or any other usage of the alias

import moduleB : TestTemplate;

is sufficient for main.d and just running dmd -c main.d moduleA.d moduleB.d. We just need sth. to check visibility.

Copy link
Member

@MartinNowak MartinNowak left a comment

Choose a reason for hiding this comment

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

Let's go for now.

@timotheecour
Copy link
Contributor Author

@MartinNowak changed to import imports.test18480a : TestTemplate; and added // REQUIRED_ARGS: -i

@timotheecour
Copy link
Contributor Author

@JinShil
Copy link
Contributor

JinShil commented Feb 24, 2018

I think the correct place to address this problem is in AliasDeclaration.overloadInsert and check if the overload being inserted will recursively refer to this.

override bool overloadInsert(Dsymbol s)

I tried to create a fix, but failed. I don't see anyway to compare two symbol instances to see if they are actually pointing to the same thing.

@timotheecour
Copy link
Contributor Author

how about merging this in meantime and if you find a better fix we can always revert? this bug is serious and we shd fix before upcoming release

@MartinNowak
Copy link
Member

The FBSD error is unrelated, seems like Brad is trying to migrate or update the boxes as Github rightfully dropped SSLv23 support.

@MartinNowak MartinNowak merged commit a551a36 into dlang:stable Feb 24, 2018
@wilzbach
Copy link
Contributor

The FBSD error is unrelated, seems like Brad is trying to migrate or update the boxes as Github rightfully dropped SSLv23 support.

Yes, for those interested in following / subscribing / learning more about this -> braddr/d-tester#70

@MartinNowak
Copy link
Member

The order of what happens is as follows.

alias sym => template mod.sym from import mod : sym; is added to symbol table.
alias sym => type sym (unresolved) is overloaded with above alias (cause it's aliasee is a template which are overloadable).
type sym gets resolved and finds the overload sym in symbol table, now the second entry in the overload points to the overload itself and mostVisibleOverload happily traverses this loop ad infinitum.

This bug was there since, it has just been additionally exposed now when that loop is selectively imported. Calls to mostVisibibleOverload are inserted into basically every symbol usage though, so it was just dormant.

MartinNowak added a commit to MartinNowak/dmd that referenced this pull request Feb 24, 2018
@MartinNowak
Copy link
Member

MartinNowak commented Feb 24, 2018

It's unclear why the alias sym = sym isn't resolved before inserting it in the overload, as only overloadable aliasees should be added AFAIR.
Needs a bit more work, but here is a self-alias detection https://github.com/MartinNowak/dmd/tree/fix18480.

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

Labels

Review:WIP Work In Progress - not ready for review or pulling Severity:Bug Fix Severity:Enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants