Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
Browse files Browse the repository at this point in the history
… into fix-typeref-error
  • Loading branch information
HindujaB committed Oct 23, 2023
2 parents 9c323ad + 74c138e commit a87db26
Show file tree
Hide file tree
Showing 75 changed files with 951 additions and 239 deletions.
29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

# The Ballerina programming language

[Ballerina](https://ballerina.io/) is a statically typed, open-source cloud-native programming language developed
and supported by [WSO2](https://wso2.com/).
[Ballerina](https://ballerina.io/) is an open-source cloud-native programming language optimized for integration. It is developed and supported by [WSO2](https://wso2.com/).

With Ballerina, you could easily develop microservices, API endpoints and integrations,
and any other application for the cloud. Additionally, Ballerina has all the general-purpose
Expand All @@ -34,18 +33,6 @@ Extensible metadata enables easy integration of Ballerina programs with cloud pl
You could directly generate Docker and Kubernetes artifacts straight away from
the source code.

## Get started

You can use one of the following options to try out Ballerina.

* [Set up Ballerina](https://ballerina.io/learn/get-started/)
* [Ballerina Playground](https://play.ballerina.io/)

You can use the following resources to learn Ballerina.

* [Ballerina by Example](https://ballerina.io/learn/by-example/)
* [Ballerina learn pages and guides](https://ballerina.io/learn/)

## Download and install

For instructions on downloading and installing, see [Ballerina Downloads](https://ballerina.io/downloads/).
Expand All @@ -58,13 +45,20 @@ For more installation options, see [Installation options](https://ballerina.io/d

Try out Ballerina's development capabilities using the [Ballerina extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=WSO2.ballerina).

## Get started

You can use the following resources to learn Ballerina.

* [Ballerina by Example](https://ballerina.io/learn/by-example/)
* [Ballerina learn pages and guides](https://ballerina.io/learn/)

## Report issues and security flaws

>**Tip:** If you are unsure whether you have found a bug, search the existing issues in the GitHub repo and raise it in the [Ballerina Discord](https://discord.com/invite/wAJYFbMrG2) or [Stack Overflow](https://stackoverflow.com/questions/tagged/ballerina).
- Language, Tooling, Ballerina library, Website: <a href="https://github.com/ballerina-platform/ballerina-lang/issues">ballerina-lang</a> repo
- Extended library: <a href="https://github.com/ballerina-platform/ballerina-extended-library/issues">ballerina-extended-library</a> repo
- Security flaw: send an email to security@ballerina.io. For details, see the <a href="https://ballerina.io/security/">security policy</a>.
- Language, Tooling, Website: <a href="https://github.com/ballerina-platform/ballerina-lang/issues">ballerina-lang</a> repo
- Ballerina library: <a href="https://github.com/ballerina-platform/ballerina-standard-library/issues">ballerina-lang</a> repo
- Security flaw: send an email to security@ballerina.io. For details, see the <a href="https://ballerina.io/security-policy/">security policy</a>.


## Contribute to Ballerina
Expand All @@ -79,7 +73,6 @@ Ballerina code is distributed under [Apache license 2.0](https://github.com/ball

## Useful links

* Join [Ballerina-Dev](https://groups.google.com/g/ballerina-dev) group for technical discussions related to the Ballerina project.
* Chat live with us on our [Discord community](https://discord.com/invite/wAJYFbMrG2).
* Post technical questions on the Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag.
* For more details on how to engage with the community, see [Community](https://ballerina.io/community/).
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.ballerina.runtime.internal.scheduling;

import io.ballerina.runtime.api.async.Callback;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BFunctionPointer;
import io.ballerina.runtime.api.values.BObject;
Expand Down Expand Up @@ -91,7 +92,8 @@ private synchronized void invokeStopHandlerFunction(Strand strand, Scheduler sch
BFunctionPointer<?, ?> bFunctionPointer = stopHandlerStack.pop();
StopHandlerCallback callback = new StopHandlerCallback(strand, scheduler);
final FutureValue future = scheduler.createFuture(strand, callback, null,
((BFunctionType) bFunctionPointer.getType()).retType, null, strand.getMetadata());
((BFunctionType) TypeUtils.getImpliedType(bFunctionPointer.getType())).retType, null,
strand.getMetadata());
scheduler.scheduleLocal(new Object[]{strand}, bFunctionPointer, strand, future);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void setLength(long length) {
int newLength = (int) length;
checkFixedLength(length);
rangeCheck(length, size);
fillerValueCheck(newLength, size);
fillerValueCheck(newLength, size, newLength);
resizeInternalArray(newLength);
fillValues(newLength);
size = newLength;
Expand Down Expand Up @@ -193,9 +193,9 @@ public Type getIteratorNextReturnType() {
* helper methods that are visible to the implementation classes.
*/

protected abstract void fillValues(int newLength);
protected abstract void fillValues(int index);

protected abstract void fillerValueCheck(int newLength, int size2);
protected abstract void fillerValueCheck(int index, int size, int expectedLength);

protected abstract void resizeInternalArray(int newLength);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,15 +1105,15 @@ protected void rangeCheck(long index, int size) {
}

@Override
protected void fillerValueCheck(int index, int size) {
protected void fillerValueCheck(int index, int size, int expectedLength) {
// if the elementType doesn't have an implicit initial value & if the insertion is not a consecutive append
// to the array, then an exception will be thrown.
if (arrayType.hasFillerValue()) {
return;
}
if (index > size) {
throw ErrorHelper.getRuntimeException(ErrorReasons.ILLEGAL_LIST_INSERTION_ERROR,
ErrorCodes.ILLEGAL_ARRAY_INSERTION, size, index + 1);
ErrorCodes.ILLEGAL_ARRAY_INSERTION, size, expectedLength);
}
}

Expand Down Expand Up @@ -1172,7 +1172,7 @@ private void prepareForAdd(long index, Object value, Type sourceType, int curren

int intIndex = (int) index;
rangeCheck(index, size);
fillerValueCheck(intIndex, size);
fillerValueCheck(intIndex, size, intIndex + 1);
ensureCapacity(intIndex + 1, currentArraySize);
fillValues(intIndex);
resetSize(intIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ protected void rangeCheck(long index, int size) {
}

@Override
protected void fillerValueCheck(int index, int size) {
protected void fillerValueCheck(int index, int size, int expectedLength) {
// if there has been values added beyond the current index, that means filler values
// has already been checked. Therefore no need to check again.
// has already been checked. Therefore, no need to check again.
if (this.size >= index) {
return;
}
Expand All @@ -682,7 +682,7 @@ protected void fillerValueCheck(int index, int size) {
// to the array, then an exception will be thrown.
if (!TypeChecker.hasFillerValue(this.tupleType.getRestType()) && (index > size)) {
throw ErrorHelper.getRuntimeException(ErrorReasons.ILLEGAL_LIST_INSERTION_ERROR,
ErrorCodes.ILLEGAL_TUPLE_INSERTION, size, index + 1);
ErrorCodes.ILLEGAL_TUPLE_INSERTION, size, expectedLength);
}
}

Expand Down Expand Up @@ -759,7 +759,7 @@ private void prepareForAdd(long index, Object value, int currentArraySize) {
TypeChecker.getType(value)));
}

fillerValueCheck(intIndex, size);
fillerValueCheck(intIndex, size, intIndex + 1);
ensureCapacity(intIndex + 1, currentArraySize);
fillValues(intIndex);
resetSize(intIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,15 @@ private int runTestSuiteWithNativeImage(Package currentPackage, Target target,
if (nativeImageCommand == null) {
throw new ProjectException("GraalVM installation directory not found. Set GRAALVM_HOME as an " +
"environment variable\nHINT: To install GraalVM, follow the link: " +
"https://ballerina.io/learn/build-a-native-executable/#configure-graalvm");
"https://ballerina.io/learn/build-the-executable-locally/#configure-graalvm");
}
nativeImageCommand += File.separator + BIN_DIR_NAME + File.separator
+ (OS.contains("win") ? "native-image.cmd" : "native-image");

File commandExecutable = Paths.get(nativeImageCommand).toFile();
if (!commandExecutable.exists()) {
throw new ProjectException("Cannot find '" + commandExecutable.getName() + "' in the GRAALVM_HOME. " +
"Install it using: gu install native-image");
throw new ProjectException("Cannot find '" + commandExecutable.getName() + "' in the GRAALVM_HOME/bin "
+ "directory. Install it using: gu install native-image");
}
} catch (ProjectException e) {
throw createLauncherException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DocumentContext {
private NodeCloner nodeCloner;
private final DocumentId documentId;
private final String name;
private final String content;
private String content;
private boolean disableSyntaxTree = false;

private DocumentContext(DocumentId documentId, String name, String content, boolean disableSyntaxTree) {
Expand Down Expand Up @@ -187,4 +187,11 @@ private void reportSyntaxDiagnostics(PackageID pkgID, SyntaxTree tree, BLangDiag
DocumentContext duplicate() {
return new DocumentContext(this.documentId, this.name, syntaxTree().toSourceCode(), false);
}

void shrink() {
if (this.compilationUnit != null) {
this.compilationUnit.topLevelNodes.clear();
}
this.content = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ private void performCodeGen() {
moduleDiagnostics.add(
new PackageDiagnostic(diagnostic, moduleContext.descriptor(), moduleContext.project()));
}

//TODO: remove this once ballerina-lang#41407 is fixed
ModuleContext.shrinkDocuments(moduleContext);
}
// add compilation diagnostics
diagnostics.addAll(moduleDiagnostics);
Expand Down Expand Up @@ -553,15 +556,15 @@ private Path emitGraalExecutable(Path executableFilePath) {
if (nativeImageCommand == null) {
throw new ProjectException("GraalVM installation directory not found. Set GRAALVM_HOME as an " +
"environment variable\nHINT: To install GraalVM, follow the link: " +
"https://ballerina.io/learn/build-a-native-executable/#configure-graalvm");
"https://ballerina.io/learn/build-the-executable-locally/#configure-graalvm");
}
nativeImageCommand += File.separator + BIN_DIR_NAME + File.separator
+ (OS.contains("win") ? "native-image.cmd" : "native-image");

File commandExecutable = Paths.get(nativeImageCommand).toFile();
if (!commandExecutable.exists()) {
throw new ProjectException("cannot find '" + commandExecutable.getName() + "' in the GRAALVM_HOME. " +
"Install it using: gu install native-image");
throw new ProjectException("cannot find '" + commandExecutable.getName() + "' in the GRAALVM_HOME/bin " +
"directory. Install it using: gu install native-image");
}

String graalVMBuildOptions = project.buildOptions().graalVMBuildOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ static void loadPlatformSpecificCodeInternal(ModuleContext moduleContext, Compil
// TODO implement
}

//TODO: should be removed once we properly fix ballerina-lang#41407
static void shrinkDocuments(ModuleContext moduleContext) {
moduleContext.srcDocContextMap.values().forEach(DocumentContext::shrink);
}

Optional<MdDocumentContext> moduleMdContext() {
return Optional.ofNullable(this.moduleMdContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,8 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
INVALID_QUERY_CONSTRUCT_TYPE("BCE4055", "invalid.error.query.construct.type"),
CANNOT_USE_ALTERNATE_WAIT_ACTION_WITHIN_MULTIPLE_WAIT_ACTION("BCE4056",
"cannot.use.alternate.wait.action.within.multiple.wait.action"),
EXPRESSION_OF_FUTURE_TYPE_EXPECTED("BCE4057", "future.expression.expected")
EXPRESSION_OF_FUTURE_TYPE_EXPECTED("BCE4057", "future.expression.expected"),
INSTANTIATION_ERROR("BCE4058", "instantiation.error")
;

private String diagnosticId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ private CompiledJarFile generate(BPackageSymbol packageSymbol) {
HashMap<String, String> originalIdentifierMap = JvmDesugarPhase.encodeModuleIdentifiers(packageSymbol.bir);

// TODO Get-rid of the following assignment
packageSymbol.compiledJarFile = jvmPackageGen.generate(packageSymbol.bir, true);
CompiledJarFile compiledJarFile = jvmPackageGen.generate(packageSymbol.bir, true);

//Revert encoding identifier names
JvmDesugarPhase.replaceEncodedModuleIdentifiers(packageSymbol.bir, originalIdentifierMap);
return packageSymbol.compiledJarFile;
return compiledJarFile;
}

private void populateExternalMap(JvmPackageGen jvmPackageGen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand Down Expand Up @@ -897,6 +898,10 @@ private Executable resolveMethod(Class<?> clazz, String name, Class<?>... paramT
private List<Executable> getExecutables(Class<?> clazz, String methodName, JMethodKind kind) {

if (kind == JMethodKind.CONSTRUCTOR) {
if (Modifier.isAbstract(clazz.getModifiers())) {
throw new JInteropException(DiagnosticErrorCode.INSTANTIATION_ERROR,
"'" + clazz.getName() + "' is abstract, and cannot be instantiated");
}
return Arrays.asList(getConstructors(clazz));
} else {
List<Executable> list = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ private BLangLambdaFunction addReturnAndDefineLambda(BLangFunction function, BLa

BInvokableSymbol lambdaFunctionSymbol = createInvokableSymbol(function, pkgID, owner);
BLangLambdaFunction lambdaFunction = desugar.createLambdaFunction(function, lambdaFunctionSymbol, env);
lambdaFunction.capturedClosureEnv = env.createClone();
lambdaFunction.capturedClosureEnv = env;

pkgNode.functions.add(function);
pkgNode.topLevelNodes.add(function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,7 @@ public void visit(BLangLambdaFunction bLangLambdaFunction) {
boolean isWorker = bLangLambdaFunction.function.flagSet.contains(Flag.WORKER);
bLangLambdaFunction.enclMapSymbols = collectClosureMapSymbols(symbolEnv, enclInvokable, isWorker);
}
bLangLambdaFunction.capturedClosureEnv = null;
result = bLangLambdaFunction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private BLangExpression createClosureForDefaultValue(String closureName, String
BLangReturn returnStmt = ASTBuilderUtil.createReturnStmt(function.pos, (BLangBlockFunctionBody) function.body);
returnStmt.expr = varNode.expr;
BLangLambdaFunction lambdaFunction = createLambdaFunction(function);
lambdaFunction.capturedClosureEnv = env.createClone();
lambdaFunction.capturedClosureEnv = env;
BInvokableSymbol varSymbol = createSimpleVariable(function, lambdaFunction, false);
env.enclPkg.symbol.scope.define(function.symbol.name, function.symbol);
env.enclPkg.functions.add(function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6222,7 +6222,7 @@ private BLangNode rewriteObjectMemberAccessAsField(BLangFieldBasedAccess fieldAc

BLangLambdaFunction lambdaFunction = (BLangLambdaFunction) TreeBuilder.createLambdaFunctionNode();
lambdaFunction.function = func;
lambdaFunction.capturedClosureEnv = env.createClone();
lambdaFunction.capturedClosureEnv = env;
env.enclPkg.functions.add(func);
env.enclPkg.topLevelNodes.add(func);
//env.enclPkg.lambdaFunctions.add(lambdaFunction);
Expand Down Expand Up @@ -7809,6 +7809,7 @@ public void visit(BLangLambdaFunction bLangLambdaFunction) {
funcSymbol.addAnnotation(this.strandAnnotAttachement.annotationAttachmentSymbol);
funcSymbol.schedulerPolicy = SchedulerPolicy.ANY;
}
bLangLambdaFunction.capturedClosureEnv = null;
result = bLangLambdaFunction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.ballerinalang.model.symbols.SymbolKind;
import org.ballerinalang.model.symbols.SymbolOrigin;
import org.ballerinalang.repository.CompiledPackage;
import org.wso2.ballerinalang.compiler.CompiledJarFile;
import org.wso2.ballerinalang.compiler.bir.model.BIRNode;
import org.wso2.ballerinalang.compiler.semantics.model.types.BPackageType;
import org.wso2.ballerinalang.compiler.util.Name;
Expand Down Expand Up @@ -56,9 +55,6 @@ public class BPackageSymbol extends BTypeSymbol {
public BIRNode.BIRPackage bir; // TODO try to remove this
public BIRPackageFile birPackageFile;

// kep code generated jar binary content in memory
public CompiledJarFile compiledJarFile;

// TODO Refactor following two flags
public boolean entryPointExists = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ error.unsupported.primitive.type.reason=\
error.method.signature.not.match=\
'{ballerina/jballerina.java}'METHOD_SIGNATURE_DOES_NOT_MATCH ''{0}''

error.instantiation.error=\
'{ballerina/jballerina.java}'INSTANTIATION_ERROR ''{0}''

error.invalid.attribute.reference=\
invalid attribute reference

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"leadingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
"value": " "
}
],
"trailingMinutiae": [
Expand Down Expand Up @@ -203,7 +203,7 @@
"leadingMinutiae": [
{
"kind": "WHITESPACE_MINUTIAE",
"value": " "
"value": " "
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public function main() {
foo(object {
int i = 1;
});
int i = 1;
});
}
2 changes: 1 addition & 1 deletion distribution/zip/jballerina/bin/bal.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rem ----- if JAVA_HOME is not set we're not happy ------------------------------
:checkJava

set BALLERINA_HOME=%~sdp0..
if exist %BALLERINA_HOME%\..\..\dependencies\jdk-17.0.7+7-jree (
if exist %BALLERINA_HOME%\..\..\dependencies\jdk-17.0.7+7-jre (
set "JAVA_HOME=%BALLERINA_HOME%\..\..\dependencies\jdk-17.0.7+7-jre"
)

Expand Down
Loading

0 comments on commit a87db26

Please sign in to comment.