Skip to content
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

[WIP] Add existential structs to Checked C #683

Merged
merged 86 commits into from
Sep 20, 2019

Conversation

abeln
Copy link

@abeln abeln commented Sep 13, 2019

Design doc: https://github.com/microsoft/checkedc/wiki/%5BProposal%5D-Add-Existential-Structs-to-CheckedC

PR with tests: checkedc/checkedc#382

I'll update the PR to be more meaningful when we're closing to merging this.

Current state of the PR: there are lots of TODOs, so it'd be helpful to get feedback both on the current state of things and prioritization of issues.

@abeln
Copy link
Author

abeln commented Sep 18, 2019

@dtarditi I've addressed most of your comments. PTAL. I've added a couple of questions.
I also updated the companion PR with more tests: checkedc/checkedc#382

I'm tracking the TODOs in the master issues for existentials (#661) and generics (#644).

Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have additional feedback.

lib/Parse/ParseExpr.cpp Show resolved Hide resolved
lib/Parse/ParseExpr.cpp Outdated Show resolved Hide resolved
FreeVariablesFinder(Sema &SemaRef) : BaseTransform(SemaRef), Context(SemaRef.Context) {}

/// Returns the list of free type variables referenced in the given type.
std::vector<const TypeVariableType *> find(QualType Tpe) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use SmallVector per the LLVM programmer's manual.

@@ -478,3 +487,245 @@ QualType Sema::SubstituteTypeArgs(QualType QT, ArrayRef<TypeArgument> TypeArgs)

return TransformedQT;
}

namespace {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a RecursiveASTVisitor instead? See for example ContainersTypeVarVisitor later in this file.


/// For an existential type, add the introduced variable to the set of bound variables
/// and recurse on the inner type.
QualType TransformExistentialType(TypeLocBuilder &TLB, ExistentialTypeLoc TL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you should be able to override this to get the behavior you want.

@@ -12667,6 +12687,12 @@ TreeTransform<Derived>::TransformRangeBoundsExpr(RangeBoundsExpr *E) {
E->getRParenLoc());
}

template<typename Derived>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be code to transform the body and types of the pack expression.

lib/AST/Type.cpp Show resolved Hide resolved
lib/CodeGen/CGDebugInfo.cpp Show resolved Hide resolved
lib/CodeGen/CGDebugInfo.cpp Show resolved Hide resolved
lib/Parse/ParseDecl.cpp Outdated Show resolved Hide resolved
@abeln
Copy link
Author

abeln commented Sep 19, 2019

Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! There are a few more improvements that can be done later. I think we can commit this now.

@dtarditi dtarditi merged commit e273f31 into master Sep 20, 2019
@abeln abeln deleted the issue-661-existential-structs branch September 20, 2019 23:07
mgrang pushed a commit that referenced this pull request Sep 26, 2019
Cherry-picked from commit e273f31
Author: Abel Nieto <[email protected]>
Commit: David Tarditi <[email protected]>

    [WIP] Add existential structs to Checked C (#683)

    This large change adds support for existential struct types to Checked C.  These can be used to replace uses of void pointers in callbacks, abstract data types, and closures.  There is a corresponding commit of tests for existential types to the Checked C repo.

    This changes adds IR support, parsing support, semantic checking/typechecking support, and code generation support.  Serialization/deserialization support still needs to be implemented.   There are also a number of cleanups to do, which are documented in GitHub issues.   There are three parts to the change:
    - Support for existential types.
    - The pack operation.
    - The unpack operation, which is done as a declaration with an initializer.

    * Add a new existential type to the type hierarchy

    * Handle existential types in different places

    * More handling of new ExistentialType

    * Add new _Exists token

    * Handle existentials in a few more places

    * Handle existentials in additional places (including codegen)

    * [wip] Add an existential type to clang

    * Desugar type variable in existential

    * Fix bug in desugaring of exists

    * Add dedicated scopes for existentials

    * Rename some variables

    * [wip] Instantiate existential types

    * Fix bugs

    * Better logic for determining whether an Existential is an aggregate

    * Disambiguate between expressions and decls in the parser

    * [wip] add a pack operation and start handling it all over the compiler

    * Add support for pack in additional locations

    * Hook up pack operation in parser

    * [wip] parse pack expressions and generate ast node

    * Can now parse pack expressions

    * Codegen pack expressions

    * Slightly  better merge function for existential types

    * Better caching of type applications and existentials

    * Fix typo in comment

    * Check witness type in pack expressions

    * Add pack expression in the right place

    * [wip] parse unpack type specifiers

    * [wip] parse unpack specifiers

    * Move unpack to custom specifier

    * Differentiate between unpack variables in same scope

    * Add hacky rule for typing unpack init

    * bug fix

    * Minor fixes

    * Restructure ExistentialType to contain more than a TypeVariableType for the TypeVar

    * Fix evaluation kind resolution

    * Better canonical types for existentials

    * Simplifying generation of canonical types

    * Fix bug in creating existential type

    * Revert changes to numbering of existential type variables

    * Fix bug in allocation logic

    * Implement a visitor that computes free variables

    * Comment out logging code

    * Implement alpha renamer and wip canonical type generation

    * Hooked up canonicalization to creation of existential types

    * Fix bugs

    * handle typedefs in alpha renamer

    * handle type applications

    * fix bug

    * fix another bug

    * remoev incorrect canonicalization

    * fix bug in insertion to subst map

    * fix bug in checking witness type

    * Add TODO

    * fix codegen of type applications

    * Remove unused static variable

    * Emit parsing error while parsing existentials

    * Improve wording

    * Rename ExistTpe to ExistType

    * Improve wording

    * Improve wording

    * Add issue number to TODOs

    * Improve wording

    * Add explanation

    * Fix typo

    * Check return type of pack expressions (must be an existential)

    * Strengthen assertion

    * Tag comments with issue number

    * Tag comment

    * Improve wording

    * Replace assertion by runtime error message

    * Check that an unpack initializer has an existential type

    * Add comment about pack expressions being r-values

    * Remove unneeded comment

    * Compute type linkage info in different way

    * Tag comment

    * Improve comment

    * Tag comment

    * Check for malformed unpacks

    * Fix warning and missing symbol

    * Add missing switch case

    * Partially disable clang test

    * Fix codegen check

    * Fix typo

    * Improve handling of linkage for existentials

    * Use getAs() instead of manually getting canonical type

    * Address code review comment
mgrang pushed a commit that referenced this pull request Sep 27, 2019
Cherry-picked from commit e273f31

    This large change adds support for existential struct types to Checked C.  These can be used to replace uses of void pointers in callbacks, abstract data types, and closures.  There is a corresponding commit of tests for existential types to the Checked C repo.

    This changes adds IR support, parsing support, semantic checking/typechecking support, and code generation support.  Serialization/deserialization support still needs to be implemented.   There are also a number of cleanups to do, which are documented in GitHub issues.   There are three parts to the change:
    - Support for existential types.
    - The pack operation.
    - The unpack operation, which is done as a declaration with an initializer.
mgrang pushed a commit that referenced this pull request Sep 27, 2019
Cherry-picked from commit e273f31

    This large change adds support for existential struct types to Checked C.  These can be used to replace uses of void pointers in callbacks, abstract data types, and closures.  There is a corresponding commit of tests for existential types to the Checked C repo.

    This changes adds IR support, parsing support, semantic checking/typechecking support, and code generation support.  Serialization/deserialization support still needs to be implemented.   There are also a number of cleanups to do, which are documented in GitHub issues.   There are three parts to the change:
    - Support for existential types.
    - The pack operation.
    - The unpack operation, which is done as a declaration with an initializer.
Machiry pushed a commit to Machiry/checkedc-clang that referenced this pull request Jan 21, 2022
Enhancement for functions with single `void*` parameter or return to be converted into `_For_any` generics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants