Skip to content

Commit 1b60252

Browse files
target: a row's defaults are not replaced in place (mcpp#911 G2, revised)
`replace` of row defaults is withdrawn: a platform whose machine differs from a built-in row defines its own row (G1), as i686-none-elf now is one (G12), and an appended flag already overrides a row's where the compiler reads the last one. `mcpp why flags` keeps naming each word's layer. Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 45bfae9 commit 1b60252

23 files changed

Lines changed: 89 additions & 328 deletions

‎CHANGELOG.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
the systems and C libraries the resolved platforms define (mcpp#911 G1).
2424
- `mcpp why target` lists a request's candidates with their priorities and
2525
availability; `mcpp why flags [<unit>]` lists each word of a unit's command
26-
line and of the link line with the layer that gave it (row, replacement,
27-
platform, toolchain, package, engine). Both take `--format json`. The build
26+
line and of the link line with the layer that gave it (row, platform,
27+
toolchain, package, engine; mcpp#911 G2). A row's defaults are not replaced
28+
in place: a platform whose machine differs defines its own row (G1). Both take `--format json`. The build
2829
record and the `plan` event carry `{request, identity, provider, priority,
2930
fallback}`; build programs read `mcpp::target_provider()`
3031
(`MCPP_TARGET_PROVIDER`).
3132
- `mcpp.lock` records `[target."<request>"]` with the identity and the
3233
provider; `--locked` refuses a build that selects another identity.
33-
- `[platform.replace]` and `[target.<selector>.replace]` replace the row's
34-
defaults (`-march=`, `-mabi=`, `-mcmodel=`, its flags, `-m <emulation>`) by
35-
name; a replacement that meets no word of the row is reported (mcpp#911 G2).
3634
- A sysroot or a provider that states a hosted C environment turns off
3735
`-ffreestanding` (G3); a platform's `link.driver = "compiler"` links any row
3836
(G4); an artifact for another system is not judged by this machine's loader

‎modules/manifest/src/platform.cppm‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,6 @@ struct Runner {
124124
bool set = false;
125125
};
126126

127-
// A word of the row's defaults and the words that stand in its place
128-
// (`[platform.replace]`, `[target.<selector>.replace]`; SPEC-016 §5.2). The
129-
// row's defaults are its machine description -- `-march=`, `-mabi=`,
130-
// `-mcmodel=`, its `flags` and `-m <emulation>` -- and only they are
131-
// replaced; a convention of the engine is only added to. `with` empty: the
132-
// word is removed.
133-
struct Replacement {
134-
std::string word;
135-
std::vector<std::string> with;
136-
Origin origin;
137-
};
138-
139127
// The four flag lists of `[platform.build]` and of each of its
140128
// `[platform.build.'cfg(...)']` tables.
141129
struct Flags {
@@ -308,8 +296,6 @@ struct Statement {
308296
std::vector<CfgFlags> buildCfg;
309297
// [platform.link]
310298
Link link;
311-
// [platform.replace]: the row's defaults this statement replaces
312-
std::vector<Replacement> replace;
313299
// [platform.versions]
314300
std::map<std::string, std::string> versions;
315301
Origin versionsOrigin;
@@ -331,8 +317,7 @@ struct Statement {
331317
&& tools.empty() && build.empty() && buildCfg.empty()
332318
&& !link.driver.set && !link.flags.set && !link.start.set && !link.script.set
333319
&& !link.inputsSet && !link.exe.set && !link.shared.set && !link.sealSet
334-
&& versions.empty() && !hosted.set && defines.empty() && providers.empty()
335-
&& replace.empty();
320+
&& versions.empty() && !hosted.set && defines.empty() && providers.empty();
336321
}
337322
};
338323

@@ -367,7 +352,7 @@ constexpr bool is_layer(std::string_view k) {
367352
inline constexpr std::string_view kPlatformKeys[] = {
368353
"targets", "toolchain", "sysroot", "runner", "runners", "carrier", "plugin",
369354
"universal", "descriptor_keys", "layers", "tools", "build", "link", "versions", "hosted",
370-
"define", "provider", "priority", "replace",
355+
"define", "provider", "priority",
371356
};
372357
inline constexpr std::string_view kDefineKeys[] = {
373358
"triple", "tier", "note", "standard", "exact", "clang-triple", "object-format", "family",
@@ -388,7 +373,7 @@ inline constexpr std::string_view kHostedKeys[] = { "targets", "toolchain", "lay
388373
// override a platform. `runner`, `runners`, `toolchain` and `sysroot` are the
389374
// table's existing keys and keep their parsers.
390375
inline constexpr std::string_view kOverrideKeys[] = {
391-
"platform", "priority", "layers", "tools", "carrier", "link", "replace",
376+
"platform", "priority", "layers", "tools", "carrier", "link",
392377
};
393378

394379
// The carrier entry of `s` that serves `pair` (`<os>-<arch>`): the first whose

‎modules/manifest/src/platform_toml.cppm‎

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ struct Reader {
4646
std::expected<void, std::string>
4747
link(const mcpp::libs::toml::Table& t, std::string_view where, Link& out) const;
4848

49-
// `replace = { "<word>" = "<word>" | ["<word>", ...] | [] }`.
50-
std::expected<void, std::string>
51-
replace(const mcpp::libs::toml::Value& v, std::string_view where, std::vector<Replacement>& out) const;
52-
5349
// One entry of `link.inputs`: `{ file = "..." }` or `{ from = [...], as = "..." }`.
5450
std::expected<LinkInput, std::string>
5551
link_input(const mcpp::libs::toml::Value& e, std::string_view key) const;
@@ -321,27 +317,6 @@ Reader::flags(const toml::Table& t, std::string_view where, Flags& out,
321317
return {};
322318
}
323319

324-
std::expected<void, std::string>
325-
Reader::replace(const toml::Value& v, std::string_view where, std::vector<Replacement>& out) const {
326-
if (!v.is_table())
327-
return std::unexpected(std::format(
328-
"{} must be a table of <row word> = <words>, for example \"-mcmodel=small\" = []", where));
329-
for (auto const& [word, with] : v.as_table()) {
330-
const auto key = std::format("{}.\"{}\"", where, word);
331-
Replacement r{ word, {}, at(with, key) };
332-
if (with.is_string()) {
333-
if (!with.as_string().empty()) r.with.push_back(with.as_string());
334-
} else {
335-
auto w = strings(with, key);
336-
if (!w) return std::unexpected(w.error());
337-
r.with = std::move(*w);
338-
}
339-
std::erase_if(out, [&](const Replacement& e) { return e.word == r.word; });
340-
out.push_back(std::move(r));
341-
}
342-
return {};
343-
}
344-
345320
std::expected<LinkInput, std::string>
346321
Reader::link_input(const toml::Value& e, std::string_view key) const {
347322
if (!e.is_table())
@@ -754,8 +729,6 @@ std::expected<Statement, std::string> Reader::statement(const toml::Table& t) co
754729
if (!v.is_table()) return std::unexpected(std::format("{} must be a table", key));
755730
if (auto r = link(v.as_table(), "[platform.link]", s.link); !r)
756731
return std::unexpected(r.error());
757-
} else if (k == "replace") {
758-
if (auto r = replace(v, "[platform.replace]", s.replace); !r) return std::unexpected(r.error());
759732
} else if (k == "versions") {
760733
if (!v.is_table())
761734
return std::unexpected(std::format("{} must be a table of <package> = \"<version>\"", key));
@@ -868,8 +841,7 @@ Reader::override_(const toml::Table& t, std::string_view selector) const {
868841
} else if (k == "link") {
869842
if (!v.is_table()) return std::unexpected(std::format("{} must be a table", key));
870843
if (auto r = link(v.as_table(), key, o.fields.link); !r) return std::unexpected(r.error());
871-
} else if (k == "replace") {
872-
if (auto r = replace(v, key, o.fields.replace); !r) return std::unexpected(r.error());
844+
873845
} else if (k == "runner") {
874846
auto r = runner(v, key);
875847
if (!r) return std::unexpected(r.error());

‎modules/manifest/src/toml.cppm‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,13 +4300,6 @@ std::expected<Manifest, ManifestError> parse_document(const t::Document& documen
43004300
"[target.{}].priority must be a table, e.g. [target.{}.priority] mingw = 200", triple, triple)));
43014301
platformKeys = true;
43024302
}
4303-
// The row's defaults this selector replaces (SPEC-016 §5.2).
4304-
if (auto it = body.find("replace"); it != body.end()) {
4305-
if (!it->second.is_table())
4306-
return std::unexpected(error(origin, std::format(
4307-
"[target.{}].replace must be a table, e.g. [target.{}.replace] \"-mcmodel=small\" = []", triple, triple)));
4308-
platformKeys = true;
4309-
}
43104303
if (platformKeys || body.contains("runner") || body.contains("runners")) {
43114304
mcpp::manifest::platform::Reader rd{origin, mcpp::manifest::platform::Tier::Manifest,
43124305
&m.schemaWarnings};
@@ -4359,7 +4352,7 @@ std::expected<Manifest, ManifestError> parse_document(const t::Document& documen
43594352
static constexpr std::string_view kKnownTargetTables[] = {
43604353
"abi", "build", "build-dependencies", "carrier", "dependencies",
43614354
"dev-dependencies", "feature-deps", "feature-requires-abi",
4362-
"feature-xlings", "layers", "link", "priority", "replace", "requires_abi", "runners", "runtime",
4355+
"feature-xlings", "layers", "link", "priority", "requires_abi", "runners", "runtime",
43634356
"targets", "tools", "xlings",
43644357
};
43654358
for (auto& [key, value] : body) {
@@ -4395,7 +4388,7 @@ std::expected<Manifest, ManifestError> parse_document(const t::Document& documen
43954388
"[target.{}] has unsupported key '{}' (ignored). Supported keys: "
43964389
"cxx_runtime, linkage, min_api_level, platform, run_under, runner, sysroot, "
43974390
"toolchain, plus the [target.<triple>.runners] table for named runners and "
4398-
"the platform's layers, tools, carrier, link, priority and replace tables. "
4391+
"the platform's layers, tools, carrier, link and priority tables. "
43994392
"Per-role contracts go in [build].cxx_runtime's table form.",
44004393
triple, key));
44014394
}

‎modules/toolchain-model/src/model.cppm‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export module mcpp.toolchain.model;
44

55
import std;
66
import mcpp.toolchain.triple;
7-
export import mcpp.toolchain.target_schema;
87
export import mcpp.toolchain.base;
98
import mcpp.toolchain.platform;
109

@@ -124,10 +123,6 @@ struct Toolchain {
124123
// true`, gives a bare-metal row a C library with `main`; `-ffreestanding` is
125124
// then not added and `main` is not treated as freestanding.
126125
bool hostedC = false;
127-
// THE ROW'S DEFAULTS THE PLATFORM AND THE PROJECT REPLACE (mcpp#911 G2;
128-
// SPEC-016 §5.2): `[platform.replace]` and `[target.<selector>.replace]`,
129-
// merged in their order. Read by every producer of the row's words.
130-
std::vector<mcpp::toolchain::target::Replacement> rowReplace;
131126
// THE PAYLOAD A PAIRED PROVIDER SUPPLIES THE SYSTEM FROM (SPEC-016 §6):
132127
// clang aimed at `x86_64-windows-gnu` takes the MinGW-w64 payload as its
133128
// sysroot, C library and C++ runtime (libstdc++). Empty otherwise.

‎modules/toolchain-model/src/target_schema.cppm‎

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,39 +104,5 @@ constexpr bool available_on(const Provider& p, std::string_view host, std::strin
104104
return false;
105105
}
106106

107-
// A WORD OF A ROW'S DEFAULTS AND THE WORDS THAT STAND IN ITS PLACE (SPEC-016
108-
// §5.2). A row's defaults are its machine description: `-march=`, `-mabi=`,
109-
// `-mcmodel=`, its `flags`, and `-m <emulation>` of a link by ld.lld itself. A
110-
// platform or a project replaces one by naming it as the row gives it; `with`
111-
// empty removes it. The engine's conventions are not replaced, only added to.
112-
// `origin` names the statement, for the reports.
113-
struct Replacement {
114-
std::string word;
115-
std::vector<std::string> with;
116-
std::string origin;
117-
};
118-
119-
// `words` with each replacement applied, in order. `met`, when given, receives
120-
// the words of the replacements that met a word of the list.
121-
std::vector<std::string> replaced(std::span<const std::string> words,
122-
std::span<const Replacement> replace,
123-
std::set<std::string>* met = nullptr);
124-
125107
} // namespace mcpp::toolchain::target
126108

127-
namespace mcpp::toolchain::target {
128-
129-
std::vector<std::string> replaced(std::span<const std::string> words,
130-
std::span<const Replacement> replace,
131-
std::set<std::string>* met) {
132-
std::vector<std::string> out;
133-
for (auto const& w : words) {
134-
auto r = std::ranges::find(replace, w, &Replacement::word);
135-
if (r == replace.end()) { out.push_back(w); continue; }
136-
if (met) met->insert(w);
137-
out.insert(out.end(), r->with.begin(), r->with.end());
138-
}
139-
return out;
140-
}
141-
142-
} // namespace mcpp::toolchain::target

‎src/build/cache_key.cppm‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,7 @@ BuildAxes build_axes(const mcpp::toolchain::Toolchain& tc,
494494
if (auto ft = mcpp::toolchain::triple::parse(tc.targetTriple))
495495
if (auto spec = mcpp::freestanding::resolve(*ft))
496496
b.targetImpliedFlags =
497-
mcpp::freestanding::compile_flags(*spec, tc.targetCxxRuntime, tc.hostedC,
498-
tc.rowReplace);
497+
mcpp::freestanding::compile_flags(*spec, tc.targetCxxRuntime, tc.hostedC);
499498
b.stdlibId = tc.stdlibId;
500499
b.stdlibVersion = tc.stdlibVersion;
501500

‎src/build/flag_origins.cpp‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ import mcpp.build.compile_commands;
1515
import mcpp.manifest.flag_words;
1616
import mcpp.toolchain.model;
1717
import mcpp.toolchain.triple;
18-
import mcpp.toolchain.target_schema;
1918
import mcpp.freestanding.target;
2019
import mcpp.platform;
2120

2221
namespace mcpp::build {
2322

2423
namespace {
2524

26-
namespace ts = mcpp::toolchain::target;
2725

2826
// The options whose value is the next word: one word of the explanation.
2927
constexpr std::string_view kTakesValue[] = {
@@ -46,9 +44,8 @@ std::vector<std::string> joined(const std::vector<std::string>& tokens) {
4644
}
4745

4846
struct Layers {
49-
// The row's words as the line has them, each with the replacement it
50-
// came from (null: the row's own).
51-
std::map<std::string, const ts::Replacement*> row;
47+
// The row's machine description, as the line has it.
48+
std::set<std::string> row;
5249
std::string rowName;
5350
std::set<std::string> platform;
5451
std::string platformName;
@@ -63,11 +60,7 @@ Layers layers_of(const BuildPlan& plan) {
6360
if (auto spec = mcpp::freestanding::resolve(tc.targetTriple)) {
6461
auto words = mcpp::freestanding::row_words(*spec);
6562
for (auto& w : mcpp::freestanding::row_link_words(*spec)) words.push_back(std::move(w));
66-
for (auto const& w : words) {
67-
auto r = std::ranges::find(tc.rowReplace, w, &ts::Replacement::word);
68-
if (r == tc.rowReplace.end()) { l.row.emplace(w, nullptr); continue; }
69-
for (auto const& x : r->with) l.row.emplace(x, &*r);
70-
}
63+
l.row.insert(words.begin(), words.end());
7164
}
7265
if (plan.platform.active) {
7366
l.platformName = plan.platform.display();
@@ -85,10 +78,7 @@ Layers layers_of(const BuildPlan& plan) {
8578
}
8679

8780
FlagWord attribute(const Layers& l, const std::string& w) {
88-
if (auto r = l.row.find(w); r != l.row.end()) {
89-
if (!r->second) return { w, "row", l.rowName };
90-
return { w, "replace", std::format("{}, in place of `{}`", r->second->origin, r->second->word) };
91-
}
81+
if (l.row.contains(w)) return { w, "row", l.rowName };
9282
if (l.platform.contains(w)) return { w, "platform", l.platformName };
9383
for (auto const& root : l.toolchainRoots) {
9484
auto generic = w;

‎src/build/flag_origins.cppm‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
// package's by construction. The configuration's flags are one string the
99
// engine composes from the row, the platform, the toolchain and its own
1010
// conventions, and a word of it is attributed to the first of these that
11-
// gives it: the row's machine description (after the replacements stated for
12-
// it), the platform's `[platform.build]` and `[platform.link]`, a path inside
11+
// gives it: the row's machine description, the platform's `[platform.build]` and `[platform.link]`, a path inside
1312
// the toolchain's payload, and otherwise the engine. A word two layers give
1413
// is the first one's.
1514

@@ -23,7 +22,7 @@ export namespace mcpp::build {
2322

2423
struct FlagWord {
2524
std::string word;
26-
std::string layer; // compiler | row | replace | platform | toolchain | package | engine
25+
std::string layer; // compiler | row | platform | toolchain | package | engine
2726
std::string detail; // the row, the statement, the package, the toolchain
2827
};
2928

‎src/build/flags.cppm‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,11 +2470,10 @@ CompileFlags compute_flags_impl(const BuildPlan& plan, bool packageLinkFlags) {
24702470
if (auto spec = mcpp::freestanding::resolve(
24712471
*mcpp::toolchain::triple::parse(plan.toolchain.targetTriple))) {
24722472
const auto prefix = mcpp::freestanding::compile_prefix(
2473-
*spec, plan.toolchain.targetCxxRuntime, plan.toolchain.hostedC,
2474-
plan.toolchain.rowReplace);
2473+
*spec, plan.toolchain.targetCxxRuntime, plan.toolchain.hostedC);
24752474
f.cxx += prefix;
24762475
f.cc += prefix;
2477-
f.as += mcpp::freestanding::assemble_prefix(*spec, plan.toolchain.rowReplace);
2476+
f.as += mcpp::freestanding::assemble_prefix(*spec);
24782477

24792478
// ── The target's C library, from the TARGET, not from a package ──
24802479
//
@@ -2536,11 +2535,10 @@ CompileFlags compute_flags_impl(const BuildPlan& plan, bool packageLinkFlags) {
25362535
&& plan.platform.fields.link.driver.value == "compiler";
25372536
if (!spec->lldEmulation.empty() && !platformCompilerDriver) {
25382537
f.ldDriver = in.lld;
2539-
fsLd = mcpp::freestanding::link_flags_direct(*spec, in, ninjaEsc,
2540-
plan.toolchain.rowReplace);
2538+
fsLd = mcpp::freestanding::link_flags_direct(*spec, in, ninjaEsc);
25412539
} else {
25422540
fsLd = isClangWithCfg ? " --no-default-config" : "";
2543-
fsLd += mcpp::freestanding::link_flags(*spec, in, ninjaEsc, plan.toolchain.rowReplace);
2541+
fsLd += mcpp::freestanding::link_flags(*spec, in, ninjaEsc);
25442542
}
25452543
f.ld = fsLd + user_ldflags;
25462544
f.ldC = f.ld;

0 commit comments

Comments
 (0)