Skip to content

[REG2.067a] Issue 14039 - function is incorrectly inferred as 'pure' - #4344

Merged
WalterBright merged 5 commits into
dlang:masterfrom
9rnsr:fix14039
Jan 28, 2015
Merged

WalterBright merged 5 commits into
dlang:masterfrom
9rnsr:fix14039

Conversation

@9rnsr

@9rnsr 9rnsr commented Jan 26, 2015

Copy link
Copy Markdown
Contributor

https://issues.dlang.org/show_bug.cgi?id=14039

Fixed behavior:
If a nested function is declared inside pure function, it's implicitly marked as pure. It's introduced behavior to fix issue 9148 in #3626.

auto foo() pure {
    int x;
    auto bar() {
        // bar is also marked as pure automatically,
        // because bar can access enclosing pure funciont context.
        x = 1;
    }
}

However, if a nested function is template, pure inference should be preferred than the implicit "pure inheritance".

auto foo() pure {
    int x;
    auto bar()() {   // template function bar is impure by default
        // bar will be forced to get weak purity, only when it's trying
        // to access enclosing pure function context.
        //x = 1;

        // otherwise, bar can call impure functions and then
        // it will be inferred to impure.
        impureFuncCall().
    }
}

While debugging, I found an another purity inference regression since 2.064. This PR will also fix it.
Issue 14049 - [REG2.064] Wrong purity inference for nested lambda

9rnsr added 5 commits January 26, 2015 21:11
'X' is just undefined identifier (I had missed to replace it with actual
class/struct name), so the __traits(compiles) didn't test compiler
behavior.
It's necessary to avoid redundant errors in fail_compilation/diag0148.d.
…enceX()

By this, we can use following convenient conditions to chech inference process.

- isPureBypassingInference() == PUREimpure
  The function is already determined to impure.
- isPureBypassingInference() == PUREfwdref
  The function is in inference process.
- isPureBypassingInference() >= PUREfwdref
  The function is in inference process or determined to pure.
- isPureBypassingInference() >= PUREweak
  The function is already determined to pure.
Fixes the interaction between issue 9148 behavior (more precise pure attribute annotation for nested functions) and purity inference.
@9rnsr

9rnsr commented Jan 26, 2015

Copy link
Copy Markdown
Contributor Author

@tgehr Could you review the adjusted compiler behavior?

@WalterBright

Copy link
Copy Markdown
Member

Auto-merge toggled on

WalterBright added a commit that referenced this pull request Jan 28, 2015
[REG2.067a] Issue 14039 - function is incorrectly inferred as 'pure'
@WalterBright
WalterBright merged commit dfebd9c into dlang:master Jan 28, 2015
@9rnsr
9rnsr deleted the fix14039 branch January 29, 2015 01:41
gulugulubing pushed a commit to gulugulubing/dmd that referenced this pull request Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants