Files
swift-mirror/include/swift/Basic/PlaygroundOptions.def
Anders Bertelrud a363603c14 [Playgrounds] Add a new -playground-option flag to control which transforms to apply (#69355)
Generalize the existing `-playground-high-performance` flag into a set of options that control various aspects of the "playground transformation" in Sema.

This commit adds the first two of those controllable parts of the transform, matching what the existing flag already controls (scope entry/exit and function arguments), but in an extensible way. The intent is for this to be a scalable way to control a larger set of upcoming options.

So instead of a single flag, we represent the playground transform options as a set of well-defined choices, with a new `-playground-option` flag to individually enable or disable those options (when prefixed with "No", the corresponding option is instead disabled). Enabling an already-enabled option or disabling an already-disabled option is a no-op.

For compatibility, the existing `-playground-high-performance` flag causes "expensive" transforms to be disabled, as before. We can also leave it as a useful shorthand to include or exclude new options even in the future, based on their cost. There is a comment on the old function indicating that new code should use the more general form, but it remains for clients like LLDB until they can switch over.

The machinery for implementing the playground options is similar to how `Features.def` works, with a new `PlaygroundOptions.def` that defines the supported playground transform options.  Each playground definition specifies the name and description, as well as whether the option is enabled by default, and whether it's also enabled in the "high performance" case.

Adding a new option in the future only requires adding it to `PlaygroundOptions.def`, deciding whether it should be on or off by default, deciding whether it should also be on or off in `-playground-high-performance` mode, and checking for its presence from the appropriate places in `PlaygroundTransform.cpp`.

Note that this is intended to control the types of user-visible results that the invoker of the compiler wants, from an externally detectable standpoint. Other flags, such as whether or not to use the extended form of the callbacks, remain as experimental features, since those deal with the mechanics and not the desired observed behavior.

rdar://109911673
2023-11-15 13:02:34 -08:00

41 lines
1.7 KiB
C++

//===--- PlaygroundOptions.def - Playground Transform Options ---*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines options that can be specified for the playground transform.
//
//
// PLAYGROUND_OPTION(OptionName, Description, DefaultOn, HighPerfOn)
//
// The PLAYGROUND_OPTION macro describes each named option that controls
// an aspect of the "playground transform" step in Sema.
//
// OptionName: The name of this playground transform option (both in source
// code and as a `-playground` parameter), e.g. ScopeEvents
// Description: A string literal that describes the option, e.g. "Enables
// logging of scope entry and exit events"
// DefaultOn: Whether the option is enabled by default
// HighPerfOn: Whether the option is enabled in "high performance" mode
//
//===----------------------------------------------------------------------===//
#ifndef PLAYGROUND_OPTION
# error define PLAYGROUND_OPTION before including PlaygroundOptions.def
#endif
PLAYGROUND_OPTION(ScopeEvents, "Scope entry/exit events",
/* enabled by default */ true, /* enabled in high-perf mode */ false)
PLAYGROUND_OPTION(FunctionParameters, "Values of function parameters",
/* enabled by default */ true, /* enabled in high-perf mode */ false)
#undef PLAYGROUND_OPTION