-
Notifications
You must be signed in to change notification settings - Fork 1.5k
File concatenation principle #6031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Principle: File concatenation should preserve meaning | ||
|
||
<!-- | ||
Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
Exceptions. See /LICENSE for license information. | ||
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
--> | ||
|
||
<!-- toc --> | ||
|
||
## Table of contents | ||
|
||
- [Abstract](#abstract) | ||
- [Background](#background) | ||
- [Principle](#principle) | ||
- [Applications of these principles](#applications-of-these-principles) | ||
|
||
<!-- tocstop --> | ||
|
||
## Abstract | ||
|
||
It's always possible to concat together Carbon source files without changing the meaning of or diagnostics applied to the code. | ||
|
||
## Background | ||
danakj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In C++, it is a common practice to concatenate files together in order to | ||
recreate and distribute a bug repro or to build a piece of C++ code in an | ||
environment without the requirement of a build system. This allows code taken | ||
from any build environment to be easily compiled by a developer in any other | ||
environment, through a single compiler invocation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also mention minimization? |
||
|
||
The reason this works is largely historical, as #include performs a textual | ||
inclusion, but it can be maintained without textual includes as well. | ||
|
||
## Principle | ||
|
||
Concatenating any two Carbon files together will not change the meaning of the | ||
code in either file. It will be required to order the concatenation so that | ||
dependencies are ordered first, in order to maintain the information | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may be worth saying a bit more about imports. Can adding imports lead to ambiguities that create diagnostics? |
||
accumulation principle. There is always an ordering that allows any Carbon | ||
project to be fully concatenated into a single Carbon source file and thus built | ||
with a single compiler invocation. | ||
Comment on lines
+41
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we have a plan to support multiple packages in a single file. |
||
|
||
## Applications of these principles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add something about the example that led us to forming the principle? |
||
|
||
Carbon uses syntax to denote the start of a library or package, which functions | ||
at the top of a file or in the middle of a file in the same way. Language rules | ||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really true. You are only allowed to put the header lines before other declarations, and only once. I think the idea should be closer to saying that there should be a purely mechanical process for combining two files. |
||
may change behaviour and/or diagnostics based on the relationship of code | ||
between libraries or packages, but not between files. |
Uh oh!
There was an error while loading. Please reload this page.