Commit Graph

21 Commits

Author SHA1 Message Date
Doug Gregor
e7be8f32f1 Provide the lexical context to macro expansions 2024-02-02 16:03:29 -08:00
Steven Wu
407674ea52 [Test] Fix the wrong subsitution of swift-frontend-target in tests
There is no `%swift-frontend-target` subsitution in test, which is
actually `%target-swift-frontend`. The wrong spelling is actually
interpreted by lit as `%swift`-frontend-target, and surprising didn't
break any tests as the last argument from subsitution is
`-define-availability` so it just leads to an very akward availability
definition.
2023-12-18 16:07:48 -08:00
Rintaro Ishizaki
c587705924 Revert "XFAIL macro tests failing in ASAN bot"
This reverts commit 26122f6f80.
2023-12-04 13:38:54 -08:00
Becca Royal-Gordon
26122f6f80 XFAIL macro tests failing in ASAN bot 2023-12-04 11:08:27 -08:00
Daniel Rodríguez Troitiño
5d2e4a380c [test] Replace %swift-build-cxx-plugin with %swift-build-c-plugin (#70188)
As pointed out in https://github.com/apple/swift/pull/70136#discussion_r1411417454
the substitution name does not make sense because we are compiling
C code, not C++.

This should not introduce any behavioural changes.
2023-12-04 09:24:35 -08:00
Saleem Abdulrasool
af79bc2d3f test: introduce a helper for building mock plugins
Introduce a helper for mock plugins as `-rpath` is not a portable
construct.  This allows running more of the macro tests on Windows.
2023-09-04 11:02:25 -07:00
Saleem Abdulrasool
466ef0c5a9 test: loosen expectations to support Windows
The paths are not handled uniformly which makes it difficult to match
the build directory pattern.  This is needed to handle the tests on
Windows.
2023-09-04 08:16:28 -07:00
Saleem Abdulrasool
bc9ee85aa4 Merge pull request #68308 from compnerd/tee
tests: remove gratuitous use of `tee`
2023-09-04 07:58:35 -07:00
Saleem Abdulrasool
046b3ffd27 tests: remove gratuitous use of tee
Replace the use of `tee` with proper redirection for the output.  This
reduces the dependency on Unix tools for portability.
2023-09-03 20:57:06 -07:00
Saleem Abdulrasool
2ed10a72b1 tests: add missing env
The `env` is required to set the environment variable as executing with
environment variables is a SysV Shell thing and is not generally
portable.  This is required to support Windows.
2023-09-03 20:55:19 -07:00
Doug Gregor
339d31fabb [Macros] Add a frontend flag -Rmacro-loading to remark on macro resolution
Macro implementations can come from various locations associated with
different search paths. Add a frontend flag `-Rmacro-loading` to emit
a remark when each macro implementation module is resolved, providing
the kind of macro (shared library, executable, shared library loaded
via the plugin server) and appropriate paths. This allows one to tell
from the build load which macros are used.

Addresses rdar://110780311.
2023-08-25 15:09:49 -07:00
Rintaro Ishizaki
eefe9dc7ef [Macros] Attached macro expansions return single string
* Move collapse(expansions:for:attachedTo:) to SwiftSyntaxMacroExpansion
* SwiftSyntaxMacroExpansion.expandAttachedMacro() now perform collapsing
* SwiftSyntaxMacroExpansion.expandAttachedMacroWithoutCollapsing()
  to keep old behavior
* IPC request 'getCapability' now sends the host protocol version
* Unified IPC response 'macroExpansionResult' that returns single string
  for both 'expandFreestandingMacro' and 'expandAttachedMacro'
* Compiler accepts old 'expandFreestandingMacroResult' and
  'expandAttachedMacroResult' to keep compatibility
* Plugins check the compiler's protcol version to see if it suppports
  'macroExpansionResult', and fall back to old behavior if necessary
2023-06-26 11:04:59 -07:00
Doug Gregor
3c04cff8dd [Macros] Provide the freestanding macro role for expansion operations.
The compiler knows (from a macro declaration) what freestanding macro
role a macro implementation is expected to implement. Pass that through
to the macro expansion code itself, rather than guessing based on the
protocol conformances of the implementation type. We already use this
approach with attached macros, so this is more of the same.

Eliminates a crash and improves diagnostics when the freestanding macro
role and its implementation are out of sync, fixing rdar://110418969.
2023-06-09 12:59:56 -07:00
Ben Barham
e5a28caa9a [Test] Fix swift_swift_parser feature and use in tests
The macro tests were all using "REQUIRES: OS=macosx" as a proxy for
"have the Swift Swift parser". There was an existing feature for this,
but it was just checking whether the path was passed through. Fix that
to use the same variable as in CMake.

Also remove all extraneous `-I` and `-L` to the host libs in the target
invocations.
2023-04-03 09:25:03 -07:00
Rintaro Ishizaki
1d2fd4223f [Test] Add %host_triple and %host_sdkroot substitutions
Macro tests need to build host libraries/tools. We can't use %target-*
substitutions for that.

rdar://107398734
2023-03-31 07:41:41 -07:00
Rintaro Ishizaki
d5b8c84d5b [Macros] Use SWIFT_DUMP_PLUGIN_MESSAGING to test exectuable plugins
And stop using '-dump-macro-expansions'
2023-03-24 16:39:30 -07:00
Doug Gregor
f88d2c638f Clean up feature flags for macros.
Enable expression macros by default, and add separate feature flags for
attached and freestanding macros.
2023-03-02 14:34:59 -08:00
Rintaro Ishizaki
761cbb0ade [Macros] Add a library to make simple executable plugins for testing
Add `_swiftMockPlugin` library.
Usage:
  #include "swift/swift-c/MockPlugin/MockPlugin.h"

  MOCK_PLUGIN([
    {"expect": {...},
     "response: {...}}
  ])
2023-02-26 12:17:24 -08:00
Rintaro Ishizaki
f25af9f491 [Macros] Update executable plugin test to use the python running 'lit'
Also, update 'mock_plugin.py' to support python2

rdar://105870339
2023-02-24 09:27:01 -08:00
Rintaro Ishizaki
fdafe04b83 [Test] Disable macro executable plugin test (#63885)
Temporality disable the test while investigating
rdar://105870339
2023-02-24 09:57:00 -06:00
Rintaro Ishizaki
0e31393024 [Macros] Add executable plugin support
Executable compiler plugins are programs invoked by the host compiler
and communicate with the host with IPC via standard IO (stdin/stdout.)
Each message is serialized in JSON, prefixed with a header which is a
64bit little-endian integer indicating the size of the message.

* Basic/ExecuteWithPipe: External program invocation. Lik
  llvm::sys::ExecuteNoWait() but establishing pipes to the child's
  stdin/stdout
* Basic/Sandbox: Sandboxed execution helper. Create command line
  arguments to be executed in sandbox environment (similar to SwiftPM's
  pluging sandbox)
* AST/PluginRepository: ASTContext independent plugin manager
* ASTGen/PluginHost: Communication with the plugin. Messages are
  serialized by ASTGen/LLVMJSON

rdar://101508815
2023-02-22 10:22:14 -08:00