Commit Graph

974 Commits

Author SHA1 Message Date
David Zarzycki
7a5d9680e1 [Sema] NFC: Reorder misc bits for better code gen
As a general rule, if one wants packs miscellaneous bits into what is
otherwise just a number, the low bits are preferable over the high bits,
at least on x86. On ppc64/ppc64le, the results are more of a wash. For
reference:

struct X {
    unsigned kind : 3;
    unsigned level : 29;
};

X example(X x, unsigned y) {
    x.level += y;
    return x;
}

bool example(X x) {
    return x.level > 1;
}

==== x86_64 with 'kind' first ====

_Z7example1Xj:
        leal    (%rdi,%rsi,8), %eax
        retq

_Z7example1X:
        cmpl    $15, %edi
        seta    %al
        retq

==== x86_64 with 'kind' last ====

_Z7example1Xj:
        leal    (%rsi,%rdi), %eax
        andl    $536870911, %eax        # imm = 0x1FFFFFFF
        andl    $-536870912, %edi       # imm = 0xE0000000
        orl     %edi, %eax
        retq

_Z7example1X:
        testl   $536870910, %edi        # imm = 0x1FFFFFFE
        setne   %al
        retq

==== PPC64 with 'kind' first ====

_Z7example1Xj:
        add 5, 5, 4
        rlwimi 5, 4, 0, 0, 2
        stw 5, 0(3)
        blr

_Z7example1X:
        rlwinm 3, 3, 0, 3, 30
        cntlzw  3, 3
        srwi 3, 3, 5
        xori 3, 3, 1
        blr

==== PPC64 with 'kind' last ====

_Z7example1Xj:
        slwi 5, 5, 3
        add 4, 5, 4
        stw 4, 0(3)
        blr

_Z7example1X:
        clrldi  3, 3, 32
        subfic 3, 3, 15
        rldicl 3, 3, 1, 63
        blr

==== PPC64LE with 'kind' first ====

_Z7example1Xj:
        slwi 4, 4, 3
        add 3, 4, 3
        blr

_Z7example1X:
        clrldi  3, 3, 32
        subfic 3, 3, 15
        rldicl 3, 3, 1, 63
        blr

==== PPC64LE with 'kind' last ====

_Z7example1Xj:
        add 4, 4, 3
        rlwimi 3, 4, 0, 3, 31
        blr

_Z7example1X:
        rlwinm 3, 3, 0, 3, 30
        cntlzw  3, 3
        srwi 3, 3, 5
        xori 3, 3, 1
        blr
2018-05-17 16:04:28 -04:00
Mark Lacey
08f80ec361 Properly handle subscripts when avoiding IUO-to-Any coercion warnings.
Ensure that we grab the decl from the subscript expression so that we
can check whether it returns an IUO.

Also add tests for subscripts and failable inits.
2018-05-07 18:10:57 -07:00
Mark Lacey
a61a6d536e Conditionalize warnings for IUO-to-Any coercion on Swift version.
These warnings are turning out to be pretty noisy for code that
declares IUOs (e.g. for @IBOutlets) and then passes them to
Objective-C APIs with parameters declared as _Nonnull id.

Since we bridge non-nil values successfully in most cases, and
previuosly written and correctly executing code is either not seeing
nil values passed in or are handling the nil (which is bridged as
NSNull), it seems like a nuisance to warn about these for existing
Swift versions.

We'll conditionalize the warning, and then users can deal with these
when moving to the new language version.

Fixes: rdar://problem/39886178
2018-05-07 15:49:56 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Pavel Yaskevich
02b2aa7485 [MiscDiagnostics] Switch to use AnyFunctionType::getParams() instead of getInput() 2018-04-26 17:33:08 -07:00
David Zarzycki
9a8a9d44b9 Merge pull request #16058 from davezarzycki/qoi_formalize_ReferenceOwnership_diags
[Diag] QoI: Add ReferenceOwnership to DiagnosticArgumentKind
2018-04-20 11:02:48 -04:00
David Zarzycki
e326954bd0 [Diag] QoI: Add ReferenceOwnership to DiagnosticArgumentKind
By formalizing ReferenceOwnership as a diagnostic argument kind, we get
less boilerplate, better type safety, better output consistency, and
last but not least: future proofing.
2018-04-20 08:32:43 -04:00
Huon Wilson
fe00f53e48 [AST] Use flags instead of booleans for UnqualifiedLookup. 2018-04-09 10:58:49 +10:00
Hamish
4f8ad1afec [Sema] Revise #14875 in response to feedback
- Diagnose on the location of the '=' equals sign for assignments
- Use the variable decl as the location for the note
- Make AST node params 'const'
2018-04-02 23:05:33 +01:00
Hamish
92931b7434 Merge remote-tracking branch 'upstream/master' into warn-weak-insta-dealloc 2018-04-02 18:06:45 +01:00
Doug Gregor
b2b69e8abf Rename BoundNameAliasType to NameAliasType.
NameAliasType is dead! Long live NameAliasType!
2018-03-25 21:35:17 -07:00
Doug Gregor
c43f96a855 [AST] Remove now-unused NameAliasType. 2018-03-25 21:35:16 -07:00
Slava Pestov
6b899b625e Merge pull request #15435 from slavapestov/one-more-base-identifier
Sema: Change a getBaseIdentifier() to userFacingName()
2018-03-22 19:08:52 -07:00
Slava Pestov
7d9599a93d Sema: Change a getBaseIdentifier() to userFacingName() 2018-03-22 14:19:38 -07:00
Doug Gregor
253bd10bd3 Cope with BoundNameAliasType in more places that handle NameAliasType. 2018-03-21 23:49:33 -07:00
Mark Lacey
994c2d1acd Improve type join for function types.
It is still not completely general, but this moves things along a
little bit.
2018-03-21 11:51:54 -07:00
Slava Pestov
d118654fa8 Sema: Peephole for 'nil' literal of Optional type 2018-03-18 00:13:55 -07:00
Slava Pestov
615d068d63 Sema: Replace some uses of getBaseIdentifier() with userFacingName() 2018-03-14 22:26:58 -07:00
Hamish
48f08bdbc7 [Sema] Diagnose immediate deallocation of instances assigned to non-owning variables
When performing a binding/assignment to a weak or unowned variable/property from an initialiser call, emit a warning that the instance will be immediately deallocated.
2018-03-08 16:32:35 +00:00
Sho Ikeda
74ba135008 Merge pull request #15040 from ikesyo/gardening-not-empty
[gardening] Use `!empty()` over `size() > 0`
2018-03-08 18:47:12 +09:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Slava Pestov
26e69d9667 Sema: Diagnose self.init and super.init inside closures
Fixes <rdar://problem/27420414>.
2018-03-06 18:20:07 -08:00
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
be8defb29e Rename lookThroughAllAnyOptionalTypes to lookThroughAllOptionalTypes. 2018-02-05 23:59:01 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Hamish
416cb7f156 [Sema] Update Optional-to-Any tests for #14299
As IUOs types are no longer generated, we don't show them in diagnostics.
2018-02-02 20:00:02 +00:00
Hamish
7d3785a15e [Sema] Enable Optional-to-Any diagnostics for IUOs
For example, the implicit coercion from `Int!` to `Any` now produces a warning. Previously a warning wasn't emitted despite the optional being implicitly erased to `Any` (but warnings were emitted in some other cases, such as `Int?!` to `Any?`; this commit fixes that inconsistency).
2018-02-02 14:07:03 +00:00
Hamish
115836210f [Sema] Improve Optional-to-Any diagnostics for collections
When implicitly coercing a collection of optional elements to a collection of less-optional `Any` elements, e.g `[Any?]` to `[Any]`, emit a slightly better diagnostic:

Expression implicitly coerced from '[Any?]' to '[Any]'

and allow for silencing of the diagnostic with an explicit coercion, e.g `as [Any]`.
2018-02-02 14:07:02 +00:00
Hamish
016af6bfae [Sema] Improve Optional-to-Any diagnostics for nested optionals
When implicitly coercing a nested optional to a less optional `Any`, e.g `Any??` to `Any?`, emit a slightly better diagnostic:

Expression implicitly coerced from 'Any??' to 'Any?'

and allow for silencing of the diagnostic with an explicit coercion, e.g `as Any?`.
2018-02-02 14:07:01 +00:00
Hamish
1891c3820b [Sema] Change Optional-to-Any diagnostics to take a variable destination type
This will let us customise the diagnostic for collections and nested optionals.
2018-02-02 14:07:00 +00:00
Hamish
e0f9732eed [Sema] Refactor Optional-to-Any diagnostic logic (NFC) 2018-02-02 14:07:00 +00:00
Mark Lacey
3aa8cfd72d Fix one source of problems with allowing @noescape functions to escape.
We have other issues with Any and generics, but those will require
some additional work to get reasonable diagnostics.

Fixes part of rdar://24097075.
2018-01-23 09:26:11 -08:00
gregomni
0c3c0fd59b Support for fallthrough into cases with pattern variables. 2018-01-20 11:10:00 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
John McCall
02d7fe36ba Extend the addObserver/removeObserver to AnyObject lookup idioms.
rdar://33850465
2017-11-29 18:04:22 -05:00
Doug Gregor
3882c2922c [Type checker] Teach optional-promotion warning to understand member operators.
Fixes a diagnostics regression for expressions such as "x != nil"
(where x is non-optional), due to moving Optional's == into Optional
itself.
2017-11-17 10:52:05 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00
Doug Gregor
c8e21e7b57 [Type checker] Teach optional-promotion warning to understand member operators.
Fixes a diagnostics regression for expressions such as "x != nil"
(where x is non-optional), due to moving Optional's == into Optional
itself.
2017-11-14 16:23:20 -08:00
Doug Gregor
a49455e3b2 [Clang importer] Move the "all properties" lists into the name importer.
Swift's ASTContext contained all of the logic to find the complete list
of properties for an Objective-C class, which is used by the Clang importer
to influence the mapping of Objective-C names into Swift. Swift's
ASTContext also included a *cache* for this information, indexed by
the Clang `ObjCInterfaceDecl *`. However, this cache was getting
populated/queried from the Clang importer's name importer, such that
the keys would be Clang declarations used to build modules and then
deallocated. If that memory eventually gets reused for a different
`ObjCInterfaceDecl *`, we would get incorrect/stale all-properties
information.

Almost Surely fixes rdar://problem/35347167, which is a
nondeterministic failure where UIView's `addGestureRecognizer(_:)` gets
occasionally imported as `add(_:)`.
2017-11-08 15:25:15 -08:00
Hamish
d734631120 [Sema] Allow non-escaping functions to be passed as subscript arguments 2017-11-02 11:04:53 +00:00
Tony Allevato
715ba632dd Merge branch 'master' into synthesize-equatable-hashable 2017-10-09 15:57:36 -07:00
Brian King
a5a6684fce Improve diagnostic language 2017-09-26 20:47:09 -04:00
Brian King
c5397ba41b Clean up implementation 2017-09-26 20:46:40 -04:00
Brian King
4f20f670e7 Generate a fix-it to change the first getter usage into the setter parameter. 2017-09-25 20:19:36 -04:00
Brian King
b894bd038b Update error message 2017-09-25 19:21:16 -04:00
Brian King
f1f64ce8a6 Change warning to only be reported if the parameter is unused but the getter is used. 2017-09-25 19:20:58 -04:00
Brian King
a79d2a8c44 Generate a warning if the implicit setter argument 'newValue' is not used. 2017-09-25 19:20:50 -04:00
Tony Allevato
f74b3fb3c1 [Sema] Only emit warnings for implicit self use in getters
This fixes a pre-existing bug where implicit DeclRefExprs involving
*any* expression of the same type within a getter were flagged with
warnings, even if they were references to something other than "self".
2017-09-24 17:31:19 -07:00
Slava Pestov
55916fa128 Sema: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00