Commit Graph

10 Commits

Author SHA1 Message Date
Becca Royal-Gordon
da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00
Doug Gregor
f39fe1a755 [Tests] Put NSObject Equatable/Hashable back in the ObjectiveC module.
Technically, these operations belong in the ObjectiveC module, where NSObject
is defined. Keep them there. However, we need to build the mock ObjectiveC
overlay with `-disable-objc-attr-requires-foundation-module` now.
2018-08-01 09:25:28 -07:00
Slava Pestov
5964c00091 Migrate PrintAsObjC tests to Swift 4
I didn't migrate test/PrintAsObjC/versioned.swift, because it
explicitly checks the Swift 3 projection of some APIs.
2018-06-26 16:57:04 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Rintaro Ishizaki
3337d0330f [test] Add missing ':' for FileCheck directives (#10572)
In FileCheck tests, check prefixes must be immediately followed by ':'.
2017-06-27 07:25:07 +09:00
Dmitri Gribenko
486cab447d tests: replace 'rm -rf %t && mkdir -p %t' with '%empty-directory(%t)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Dmitri Gribenko
55864d10cb Tests: use 'mkdir -p' 2016-09-02 21:36:45 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Jordan Rose
8282160de8 [PrintAsObjC] Handle circularities introduced by ObjC generics.
Like Swift generics, Objective-C generics may have constraints; unlike
Swift generics, Objective-C doesn't do separate parsing and
type-checking passes. This means that any generic arguments for
constrained generic parameters must be fully-defined, in order to
check that they satisfy the constraints.

This commit addresses this problem with three different mechanisms,
one for each kind of declaration that might run into this issue:

- For classes, if a member references a type with constrained generic
  parameter, and the corresponding argument type hasn't been printed
  yet, that member is "delayed", which means it is put into a category
  at the end of the file.

- Protocols cannot have categories, so for protocols we instead see if
  we can print the definition of the other type first. To break
  circular dependencies, the printer will not attempt this if both the
  type and the protocol are already being depended on. This isn't
  perfect (see below).

- Rather than delaying members of extensions, we just delay them
  wholesale. This keeps related members together, but also has
  problems (see below).

These approaches solve the most common cases while still not crashing
in the uncommon ones. However, there are still a number of problems:

- The protocol heuristic is overly negative, which means we may generate
  an invalid header even when there's a reasonable ordering. For example,
  a single class might inherit from a class A and conform to protocol P,
  and protocol P depends on class A as a generic argument. In this case,
  defining class A first is the right thing to do, but it's possible for
  the printer to decide that there's circularity here and just forward-
  declare A instead.

- Protocols really can be circular. This can be fixed by printing a
  forward-declared protocol alongside the generic constraints, i.e.
  'id <MoreThanNSCopying, NSCopying>' instead of just
  'id <MoreThanNSCopying>'.

- Extensions can introduce protocols as well. This is not modeled at
  all; if a member depends on a protocol conformance, it's assumed
  that simply printing the class would be sufficient. This could be
  fixed by checking how a generic argument satisfies its constraints,
  possibly delaying individual members from extensions in order to
  print them sooner.

- More cases I haven't thought about.

Test cases for some of these problems are in the new
circularity-errors.swift file, mostly to make sure the ObjC printer
doesn't crash when it encounters them.

rdar://problem/27109377
2016-08-09 10:41:09 -07:00