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

File content is loaded into special variables #6275

Merged

Conversation

miqm
Copy link
Collaborator

@miqm miqm commented Mar 23, 2022

Contributing a Pull Request

If you haven't already, read the full contribution guide. The guide may have changed since the last time you read it, so please double-check. Once you are done and ready to submit your PR, run through the relevant checklist below.

Contributing a feature

File loading functions are now loading files into special variables starting with $ sign to avoid being overlapped by users. Then, in place where function is actually called, only variable access is emitted.
This will help to avoid duplicating file content when load functions are used in variables that need to be inlined.

If the loadTextContent or loadFileAsBase64 is used directly in a variable declaration (var file = loadTextContent('file.txt')) then no special symbol is emitted.

Fixes #5412

  • I have opened a new issue for the proposal, or commented on an existing one, and ensured that the Bicep maintainers are good with the design of the feature being implemented
  • I have included "Fixes #{issue_number}" in the PR description, so GitHub can link to the issue and close it when the PR is merged
  • I have appropriate test coverage of my new feature

semanticModel.TypeManager.GetMatchedFunctionOverload(syntax) is { VariableGenerator: { } } functionOverload)
{
var variable = functionOverload.VariableGenerator(syntax, symbol, semanticModel.GetTypeInfo(syntax));
variables.Add(syntax, new InternalVariableSymbol($"$fxv#{variables.Count}", variable));
Copy link
Member

Choose a reason for hiding this comment

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

fxv

Why "fxv"? (No issue - just curious)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fx - function, v - variable

@miqm miqm requested review from shenglol and majastrz April 13, 2022 20:30
@miqm
Copy link
Collaborator Author

miqm commented Apr 13, 2022

@majastrz @shenglol - I updated the PR, added also optimisation to not create special variables when function is used directly in variable declaration.

@miqm miqm marked this pull request as ready for review April 14, 2022 09:07
@stephaniezyen stephaniezyen added this to the v0.6 milestone Apr 14, 2022
@miqm miqm mentioned this pull request Apr 16, 2022
4 tasks
@stephaniezyen stephaniezyen removed this from the v0.6 milestone Apr 21, 2022
@miqm miqm force-pushed the feature/load-file-functions-optimisation-5412 branch from df964bf to 2a531ca Compare April 21, 2022 19:25
@@ -315,5 +314,6 @@ private ImmutableArray<ResourceMetadata> GetAllResourceMetadata()
public FileSymbol Root => this.Binder.FileSymbol;

public ResourceScope TargetScope => this.Binder.TargetScope;

Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]: Extra newline.


namespace Bicep.Core.Semantics
{
public class FunctionVariable
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind moving this to Bicep.Core.Emit as well? Otherwise it looks good to me.

Copy link
Contributor

@shenglol shenglol left a comment

Choose a reason for hiding this comment

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

:shipit:


if (variableAccessSyntax is ExplicitVariableAccessSyntax)
Copy link
Member

@majastrz majastrz Apr 21, 2022

Choose a reason for hiding this comment

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

ExplicitVariableAccessSyntax

I think we're forced into this approach because we don't have an intermediate representation between Bicep semantic model and the JSON.

I think we'll have to revisit this after we merge Anthony's IR PR, but no need to block on it.

/// <summary>
/// Represents an explicit reference to a variable
/// </summary>
public class ExplicitVariableAccessSyntax: VariableAccessSyntax
Copy link
Member

Choose a reason for hiding this comment

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

ExplicitVariableAccessSyntax

I do wonder if we should move this to an Emit-related namespace since this type of syntax node can't ever be produced by the parser.

Copy link
Member

@majastrz majastrz left a comment

Choose a reason for hiding this comment

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

:shipit:

@majastrz majastrz merged commit 54c48ed into Azure:main Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
4 participants