Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS compatibility: Use token-based instantiation for -fdelayed-template-parsing #19088

Closed
rnk opened this issue Feb 3, 2014 · 4 comments
Closed
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@rnk
Copy link
Collaborator

rnk commented Feb 3, 2014

Bugzilla Link 18714
Resolution WONTFIX
Resolved on Jun 10, 2014 15:03
Version unspecified
OS Windows NT
CC @majnemer,@DougGregor,@zmodem,@zygoloid,@timurrrr

Extended Description

Our current -fdelayed-template-parsing and -fms-compatibility approach is pretty hacky. We have lots of weird dependent nodes that don't normally appear in an eagerly instantiated clang AST, and it adds a lot of complexity without getting us all the way there in terms of compatibility.

For example, we have bugs like:
#18817
#16386
#13077

By reparsing the template with token instantiation and replay, we'd neatly solve all of these problems, hopefully with less code and fewer bugs.

I'm not planning to work on this now, but if we have enough problems, this is probably the right future direction for -fdelayed-template-parsing.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 10, 2014

Our current -fdelayed-template-parsing and -fms-compatibility approach is
pretty hacky. We have lots of weird dependent nodes that don't normally
appear in an eagerly instantiated clang AST, and it adds a lot of complexity
without getting us all the way there in terms of compatibility.

For example, we have bugs like:
#18817
#16386
#13077

By reparsing the template with token instantiation and replay, we'd neatly
solve all of these problems, hopefully with less code and fewer bugs.

Hi Reid,

Can you give some pointers on the nature of the token transformation?

Do you have a feel for the phases of token caching, instantiation and substitution that might be going on in MSVC?

I'm not planning to work on this now, but if we have enough problems, this
is probably the right future direction for -fdelayed-template-parsing.

@rnk
Copy link
Collaborator Author

rnk commented Jun 10, 2014

Can you give some pointers on the nature of the token transformation?

Do you have a feel for the phases of token caching, instantiation and
substitution that might be going on in MSVC?

First, I just want to say that I've been talked out of this approach since I filed this bug, so I'm closing it. :)

Answering your question, yes, they appear to do roughly what -fdelayed-template-parsing does: they parse class template bodies, but they slurp the tokens from C++ inline method definitions and parse them once they are instantiated and referenced. I believe you need to use typename with MSVC when appropriate in a class template body outside of C++ inline methods.

The key difference is that method bodies are never parsed prior to instantiation. The template parameters are substituted with arguments before parsing, so MSVC always knows if a nested-name-specifier is a type.

Basically, I've gotten the hang of recovering from missing 'typename' now, so I don't think it will be that hard to handle this without token substitution.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 10, 2014

So if we added a little macro-like expansion for template arguments as the tokens get replayed could that potentially lead to a lot of simplification in Sema?

It sounds potentially quite light to implement. What's footprint impact of the Sema-based approach, is it worth my taking a look?

@rnk
Copy link
Collaborator Author

rnk commented Jun 10, 2014

So if we added a little macro-like expansion for template arguments as the
tokens get replayed could that potentially lead to a lot of simplification
in Sema?

Maybe, but we might still want the complex sema bits for error recovery.

It sounds potentially quite light to implement. What's footprint impact of
the Sema-based approach, is it worth my taking a look?

The problem is that we wouldn't be able to diagnose missing typenames easily. All of our diagnostics designed for template authors would never fire, because we'd never build the dependent, pre-instantiation ASTs for inline methods.

By pursuing the AST + Sema approach, we can improve error recovery in mainline Clang when MSVC compatibility is disabled, and minimize divergence between clang with -fms-compatibility / -fdelayed-template-parsing and clang without.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@Quuxplusone Quuxplusone added the wontfix Issue is real, but we can't or won't fix it. Not invalid label Jan 20, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema" wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

3 participants