Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/project/principles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ wants to pursue, as well as those we want to exclude.
- [Prefer providing only one way to do a given thing](one_way.md)
- [One static open extension mechanism](static_open_extension.md)
- [Success criteria](success_criteria.md)
- [File concatenation](file_concatenation.md)
49 changes: 49 additions & 0 deletions docs/project/principles/file_concatenation.md
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

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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Loading