The importer handles these by first trying to look up the type by name
using Clang's Sema, but that lookup can cause diagnostics to be
emitted (usually availability diagnostics). We could try to figure out
how to propagate that to the macro when we import it, but for now just
drop the macro instead if there are any diagnostics emitted when
looking up the type.
This will be a small source compatibility break if anyone was using a
macro defined in terms of a type that's deprecated or that has partial
availability; the macro will now silently not be imported instead of
producing an unsilenceable warning.
rdar://problem/36528212
Update several functions to return a Type/bool pair with the bool
representing whether the type is one that should be implicitly
unwrapped. This bool is surfaced up to the decl importing functions,
allowing them to set the appropriate decl attribute so that the
expression type checker will consider selecting the underlying type of
the optional involved during solving if the expression doesn't type
check with the optional type.
When importing Decls, use the IUO information to set the
ImplicitlyUnwrappedOptionalAttr attribute when appropriate.
We're still generating IUO types at the moment, so this change doesn't
really have much of an affect other than the creation of those
attributes.
Rather than being smart about this, just record an import failure when
we start importing a particular macro and update it at the end. Also
add a PrettyStackTrace to make this a little easier to track down in
the future.
The old logic for importing macros that just aliased other macros
managed to handle this in a clever way, but that was never tested for
the newer logic that evaluates expressions (fa834e2f80). Macro
importing in general probably deserves some cleanup, but meanwhile we
should make sure not to crash!
rdar://problem/34986930
This has been showing up as nondeterministic failures on our Linux
bots in the clang_builtins.swift test, because that test used to
trigger typo correction! Which pulled in macros, which happened to
include some redefinitions, which resulted in this.
rdar://problem/34266952
...which didn't do the right thing in the presence of ModuleMacro,
depending on the order the macros were referenced. Already covered by
test/ClangImporter/macros.swift, but it actually seems to improve the
behavior of some of the SourceKit tests as well.
Continuing rdar://problem/32199805, which is just "get macros working
with clang::ModuleMacro".
Somehow the logic had slipped so that we were basing this decision purely
on the ImportTypeKind and not on whether the broader context is bridgeable.
This was allowing us to use bridged types when e.g. importing the results
and parameters of C function pointer types, which is really bad.
Also, when importing a reference to a typedef of block type, do not use
the typedef in a non-bridgeable context. We import typedefs of block type
as fully-bridged types, but this means that it is invalid to import a type
using the typedef in a context where the original C type must be used.
Similarly, make sure we use a properly-imported underlying type of the
typedef when the typedef itself is unavailable.
Also, extend the special behavior of block typedefs to abstract-function
typedefs, which seems to be consistent with the expected behavior of the
tests.
Finally, I changed importType to take a new Bridgeability enum instead of
a raw canFullyBridgeTypes bool. At the time, I was doing that because I
was going to make it tri-valued; that turned out to be unnecessary, but I
think it's an improvement anyway.
We don't have any way to import a macro into a different DeclContext
anyway, but even then this saves a bit of unnecessary work.
Groundwork for rdar://problem/32199805, which is that Clang has
removed a bunch of facilities for going from a SourceLocation or
MacroInfo to a Module in favor of things like clang::ModuleMacro.
...by using a null clang::QualType as a placeholder instead of a
'QualType *' that might be null.
The problematic case here was when importing builtin types, which
would use the address of a stack local in the later call to
importNumericLiteral. Rather than fix this case specifically I just
simplified the whole thing---the extra level of indirection isn't
buying us anything.
No functionality change, other than not using memory after its
lifetime has ended. Caught by ASan!
rdar://problem/31117311
integer constants, and to always look through macro definitions for them.
Also, logical comparisons now return a Boolean.
New operations: +, -, *, /, ^, >>, ==, >, >=, <, <=
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
SwiftNameLookupExtension and ClangImporter::Implementation were
friends, but as time goes on they have drifted apart. As part of the
ImportName refactoring, these are being decoupled to facilitate
multiple-name importing, and fight the existing false encapsulation
present in the Impl.
SwiftNameLookupExtension is now spun off into its own entity, and can
evolve to have and use its own de-coupled NameImporter.
Change more methods on the Impl to be static, passing down an
ASTContext if necessary. While this does ugly up the functions
slightly with the extra parameter, it decouples them from the Impl,
which has been a false abstraction when building the lookup
tables. These can all be moved to a more appropriate place in the
future.
NFC
Refactors out some definitions and types from the
ClangImporter::Implementation into a new component ImportName. Future
work will include more separation and finally some redesigning of name
determination components.
This patch fixes an importer problem which occurred for macros defined
in terms of two other macros which might not have been imported before.
For example, the macro CPU_TYPE_X86_64 (defined as CPU_TYPE_X86 |
CPU_ARCH_ABI64) in Foundation wasn't imported although the importing
logic was implemented.
importMacro is now called for each of the constituents before checking
the constant value.
Fix an assertion which is triggered when the operands of a bitwise operator have different signedness.
This is done by promoting the operands to the largest bit width (taking sign/zero extension into account) and ignoring the signedness for the operation itself.
Addresses SR-1509 by adding a heuristic to import numeric literals with a
type cast. Two new cases have been added for macros with 4 or 5 tokens
to cover cases with or without sign tokens.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.
PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
In C, macros can be redefined so long as the redefinitions are
tokenwise equivalent. Provide the Clang importer with the same ability by
determining when tokenwise equivalent macros would be imported as
different Swift declarations, and collapse them into a single
declaration.
These are contexts where we have enough information to bridge /back/
properly; that is, where we can distinguish CBool, ObjCBool, and
DarwinBoolean. In cases where we can't, we keep the three separate;
only CBool is really the same type as Bool.
This also affects current import behavior for ObjCBool, which was previously
incorrectly conflated with CBool in certain cases.
More rdar://problem/19013551
Swift SVN r30051
...and add one extra check for invalid macro info.
This reinstates the tests that were disabled in my previous commit, now that the
Clang issue has been fixed.
Finishes rdar://problem/21480635.
Patch by Jordan Rose.
Swift SVN r29705
- Macros that aren't visible won't have macro info.
- Making a module visible to Sema doesn't make it visible to the Preprocessor.
Part of rdar://problem/21480635
Patch by Jordan Rose.
Swift SVN r29703
There is some follow-up work remaining:
- test/stdlib/UnicodeTrie test kills the type checker without manual type annotations. <rdar://problem/17539704>
- test/Sema/availability test raises a type error on 'a: String == nil', which we want, but probably not as a side effect of string-to-pointer conversions. I'll fix this next.
Swift SVN r19477