Skip to content

emit build-database: a generated source does not say which authored file it is a transformed copy of (S1 ide.generated names it only among inputs) #1004

Done

Description

@speak-agent

Summary

When a rule transforms an authored C++ source into the unit the build compiles (HuxerUI's hcg does this for every source with a composable), the build database describes the generated unit and lists the authored file only as one of the step's inputs, beside the tool binary. Nothing states that the generated source is a transformed copy of that one file, so a consumer cannot tell "the file a person edits to change this unit" from "a file the step happens to read".

This issue asks for that relation to be stated: one declaration on mcpp::action, and one field in ide.generated. The field would be an S1 0.4.0 addition (MINOR, additive); the S1 text is drafted below and will land in Sunrisepeak/mcpp-language-server, as §7.2 did for #724.

Found while analysing Sunrisepeak/mcpp-language-server#95. That issue is fixed on the mcppls side without this; this is what lets the fix rest on a stated fact instead of an inference, and what a later step (semantics in the authored file) needs.

What mcpp writes today

mcpp 2026.11.20.1, Linux x86_64, buildtools/mcpp/examples/01-import of HuxerUI at 15060c27 ([build] sources = [], build.mcpp calls huxerui::rules::configure), mcpp emit build-database --format json. Paths shortened: <P> is the project, <C> is ~/.mcpp/cache/build-database/4871a6e7ddfe6d13/target/.build-mcpp/out/5ffd6c3b00114e4d/huxerui-example-import, <hcg> is the tool binary in the build cache.

Set huxerui-example-import, ide.generated:

{
  "kind": "source",
  "path": "<C>/hcg/src_app.cppm",
  "build-path": "<P>/target/.build-mcpp/out/5ffd6c3b00114e4d/huxerui-example-import/hcg/src_app.cppm",
  "generator": {
    "id": "hcg:app",
    "arguments": ["<hcg>", "--input", "<P>/src/app.cppm", "--output", "<C>/hcg/src_app.cppm"],
    "inputs": ["<P>/src/app.cppm", "<hcg>"],
    "work-directory": "…"
  }
}

The set's translation units:

source provides requires ide.role
<C>/hcg/src_app.cppm {"app": ""} std, huxerui unknown
<P>/src/main.cpp — huxerui, app non-module

<P>/src/app.cppm is not a unit, which is right: the build compiles the copy. The copy itself (after a mcpp build) is the original with #line directives that point back at <P>/src/app.cppm.

All of this is as SPEC-005 R3.12 and S1 §7.2 say. The gap is in what they say.

What a consumer cannot tell

<P>/src/app.cppm is the file the person has open. It is in no set, and it declares export module app;, which a unit of the set already provides. A consumer has three readings and the document does not choose between them:

  1. the file is not part of the build (a stray or stale source);
  2. the file is a second provider of app (a real conflict, which mcpp itself reports as a scanner error when the same file is also in [build] sources);
  3. the file is the authored form of the unit that provides app.

mcppls 0.23.0 takes reading 2: it reports ambiguous-module, gives the file no semantics and no formatting, and marks the workspace degraded (mcppls#95). The right reading is 3.

generator.inputs does not settle it:

  • it is a flat list, and here already holds two files of different kinds (the source and the tool); the hrc entries of the same set have about forty inputs for one header;
  • a step can read several C++ files (a template plus the source it instantiates) or none that are C++ (an IDL, a table), and "the only input with a C++ extension inside the project" is a guess that a second rule will break;
  • for an ordinary unit (.cpp, no module declaration) there is no module name to cross-check the guess with.

mcppls plans to use that guess as a fallback for mcpp versions without the field, and say so in its status. It should not be the contract.

Proposal

1. S1 0.4.0, §7.2: origin on a Generated object

Field Type Requirement Description
origin string MAY, kind source only Absolute path of the authored source this file is a transformed copy of: the file a person edits to change the unit compiled from path. It is one of generator.inputs. Absent when the file is not derived from one authored C++ source (generated from an interface definition, a table, a template).
line-mapping enum MAY, with origin line-directives: the generated file carries #line directives that name origin, so a position in it maps to a position in origin. none: no such mapping. Absent means unknown.

Producer:

  • MUST NOT write origin unless the step that writes the file declared it; a producer does not infer it from inputs.
  • A file named as an origin in a set SHOULD NOT also be a translation unit of that set. If the project lists it twice, that is the conflict the producer already reports.

Consumer:

  • MUST NOT report an origin file as a second provider of the modules the generated unit provides, nor as a file outside the build;
  • MAY present the generated unit's results at the origin (diagnostics and navigation through line-mapping), and MAY analyse the origin's own text with the generated unit's arguments, treating the result as approximate where the transform changes meaning.

Names are a suggestion; mcpp's own vocabulary should win where it differs. An unknown field is ignored by every conforming consumer (S1-11.2-1), so writing it is compatible with mcppls releases that do not read it.

2. mcpp::action: a way to say it

The relation is known only to the rule, so the rule declares it, for example:

mcpp::action a;
a.role = mcpp::roles::source;
a.input(source);
a.input(tool);
a.output(generated);
a.origin(source);                 // `generated` is a transformed copy of `source`
a.line_mapping("line-directives"); // optional
a.submit();
  • origin names one of the action's inputs; an action with more than one output would need the pairing spelled out (or the declaration restricted to single-output actions, which is the hcg shape).
  • No declaration, no field. Existing rule packages keep working and keep today's output.
  • SPEC-005 R3.12 then adds: an entry carries origin (and line-mapping) when its action declared them.

3. Smaller points seen in the same document (optional)

  • ide.role of the generated unit is unknown although the action declared what it provides and imports. If a declared provides were enough to write interface (or partition for an M:P name), the consumer would not need to scan a file that, before the first build, does not exist. If the declaration does not carry enough to decide, unknown is the right answer and this point is void.
  • The duplicate-provider scanner error (module 'app' is provided by package 'hui' (…/hcg/src_app.cppm) and by package 'hui' (…/src/app.cppm) … a program that links both defines the module twice) is correct, and it is what the person in mcppls#95 saw while editing [build] sources. With origin declared, the message could say what happened: the second file is the transformed copy of the first, and the manifest lists the original as a source as well.

What mcppls does with it

  • Planned for the next mcppls release, with no mcpp change: an open file that provides a module a unit of the model already provides is no longer an issue and no longer degrades the workspace, and it is formatted. The relation is inferred, and the fallback above reads generator.inputs (mcppls does not read ide.generated at all today).
  • With origin: the same, from a stated fact, and reading 1 and reading 2 stay distinguishable from reading 3.
  • Later: diagnostics, hover and navigation in the authored file. This is the part that cannot be built on a guess.

The mcppls design for this is a proposal under review and is not merged yet; none of the three steps is implemented.

Not asked for

  • No change to which files are units, to arguments, or to compile_commands.json.
  • No requirement that emit build-database run any step (R2.5 stands).
  • Nothing HuxerUI-specific in mcpp: huxerui.rules would add the one declaration to its hcg edge once the API exists.

Activity

  1. speak-agent commented on Nov 24, 2026

    @speak-agent
    MemberAuthor

    Fixed in mcpp 2026.11.23.1 (#1006). A generated unit names the authored file it is a transformed copy of: the origin field of S1's ide.generated, emitted by emit build-database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions